Password: Must and only contain numbers and letters, 6-10 bits. How do you write regular expressions?

Source: Internet
Author: User
Solving............


Reply to discussion (solution)

$pattern = '/^[a-za-z0-9]{6,10}$/';

$pattern = '/^[a-za-z0-9]{6,10}$/';


+1


$pattern = '/^[a-za-z0-9]{6,10}$/';


+1


++1

Solving............


I may not be able to articulate, must have numbers and letters, numbers and letters to have.

$pattern = '/^ (?! [0-9]+$) (?! [a-za-z]+$] [0-9a-za-z]{6,10}$/';


Separate to annotate:
^ matches the beginning of a line
(?! [0-9]+$] predict that the position is not all numbers behind
(?! [a-za-z]+$] predict that the position is not all letters behind
[0-9a-za-z] {6,10} consists of 6-10 digits or this letter
$ Match Line End position

if (Preg_match ('/\d+/', $s) && preg_match ('/[a-z]+/i ', $s)) {    echo ' yes ';} else{   echo ' No ';}

$pattern = '/^ (?! [0-9]+$) (?! [a-za-z]+$] [0-9a-za-z]{6,10}$/';


Separate to annotate:
^ matches the beginning of a line
(?! [0-9]+$] predict that the position is not all numbers behind
(?! [a-za-z]+$] predict that the position is not all letters behind
[0-9a-za-z] {6,10} consists of 6-10 digits or this letter
$ Match Line End position


Thank you! This is it, take this regular, more understanding of the next pre-check.
  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.