Regex for password must contain at least eight characters, at least one number and both lower and uppercase letters and special characters

前端 未结 30 3625
伪装坚强ぢ
伪装坚强ぢ 2020-11-21 04:28

I want a regular expression to check that:

A password contains at least eight characters, including at least one number and includes both lower and uppercase letter

相关标签:
30条回答
  • 2020-11-21 04:54

    Just a small improvement for @anubhava's answer: Since special character are limited to the ones in the keyboard, use this for any special character:

    ^(?=.*?[A-Z])(?=(.*[a-z]){1,})(?=(.*[\d]){1,})(?=(.*[\W]){1,})(?!.*\s).{8,}$

    This regex will enforce these rules:

    • At least one upper case English letter
    • At least one lower case English letter
    • At least one digit
    • At least one special character
    • Minimum eight in length
    0 讨论(0)
  • 2020-11-21 04:54

    Import the JavaScript file jquery.validate.min.js.

    You can use this method:

    $.validator.addMethod("pwcheck", function (value) {
        return /[\@\#\$\%\^\&\*\(\)\_\+\!]/.test(value) && /[a-z]/.test(value) && /[0-9]/.test(value) && /[A-Z]/.test(value)
    });
    
    1. At least one upper case English letter
    2. At least one lower case English letter
    3. At least one digit
    4. At least one special character
    0 讨论(0)
  • 2020-11-21 04:55

    Use the following Regex to satisfy the below conditions:

    Conditions:

    1. Min 1 uppercase letter.
    2. Min 1 lowercase letter.
    3. Min 1 special character.
    4. Min 1 number.
    5. Min 8 characters.
    6. Max 30 characters.

    Regex:

    /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[#$@!%&*?])[A-Za-z\d#$@!%&*?]{8,30}$/
    
    0 讨论(0)
  • 2020-11-21 04:55

    You can use the below regular expression pattern to check the password whether it matches your expectations or not.

    ((?=.*\\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[~!@#$%^&*()]).{8,20})
    
    0 讨论(0)
  • 2020-11-21 04:57

    Use this,

    ((?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[!@#$%?=*&]).{8,20})
    

    It will validate for at least one lowercase, one upper case, one number and the special charecters of (!,@,#,$,%,?,=,*,&).

    Minimum length is 8 and maximum length is 20

    0 讨论(0)
  • 2020-11-21 05:01

    Minimum eight characters, at least one letter and one number:

    "^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{8,}$"
    

    Minimum eight characters, at least one letter, one number and one special character:

    "^(?=.*[A-Za-z])(?=.*\d)(?=.*[@$!%*#?&])[A-Za-z\d@$!%*#?&]{8,}$"
    

    Minimum eight characters, at least one uppercase letter, one lowercase letter and one number:

    "^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[a-zA-Z\d]{8,}$"
    

    Minimum eight characters, at least one uppercase letter, one lowercase letter, one number and one special character:

    "^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$"
    

    Minimum eight and maximum 10 characters, at least one uppercase letter, one lowercase letter, one number and one special character:

    "^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,10}$"
    
    0 讨论(0)
提交回复
热议问题