Using Regular Expression to verify password complexity

Source: Internet
Author: User

I didn't even think about it before. You can use the Regular Expressions to verify the complex format code, which can be used in the group structure of Regular expression for this purpose, such as the condition of the cipher:

    1. There is at least one digit
    2. At least one small English letter
    3. At least one big English letter
    4. String length between 6 ~ 30 letters

Then your Regular Expression can grow like this:

^ (? =.*\d) (? =.*[a-z]) (? =.*[a-z]). {6,30}$

What is noteworthy in this paragraph of Regular Expression is that the phrase " =.*\d ", which is called "right" (Positive Lookahead), has the same width as the right (or left-hand) language. 0, that is to say that this paragraph of the language is really not to occupy the comparison of characters, but just a Regular expression in a "sentence" only, right-like (Positive Lookahead) will be judged on the right side of the word is connected to the match, If the conditions are met, it will continue.

So the explanation in this section of the law is roughly as follows:

(? =.*\d) and (? =.*[a-z]) and (? =.*[a-z]) The width is zero, so the whole string is compared to. {6,30} is the master, but it will be judged by the difference between (? =.*\d) and (? =.*[a-z]) and (? =.*[a-z]) of these three judgments before they can be done. {6,30}. So (=.*\d). *\d is to say that the right side of the text must appear a number of characters, (? =.*[a-z]) of the. *[a-z] is to say that the right side of the text must appear a small letter, (? =.*[a-z]). *[a-z] It is said that the right side of the text must appear a size letter, the last to be compared. {6,30} that is, the length of the string must be 6 to 30 characters in any character.

If your condition changes to:

    1. There is at least one digit
    2. At least one big or small English letter
    3. There is at least one special symbol
    4. String length between 6 ~ 30 letters

Then your Regular Expression can grow this way (in C # for example):

New Regex (@ "^ (? =.*\d) (? =.*[a-za-z]) (? =.*\w). { 6,30}$ ");

Do you know how to make a consistent through this? ^_^

Connected

    • Organize some of the Regex's learning resources
    • Non-backtracking right-fits and left-fits
    • Group Building structure

Using Regular Expression to verify password complexity

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.