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

前端 未结 30 3648
伪装坚强ぢ
伪装坚强ぢ 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 05:06

    Try this one:

    1. Minimum six characters
    2. At least one uppercase character
    3. At least one lowercase character
    4. At least one special character

    Expression:

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

    Optional Special Characters:

    1. At least one special character
    2. At least one number
    3. Special characters are optional
    4. Minimum six characters and maximum 16 characters

    Expression:

    "/^(?=.*\d)(?=.*[a-zA-Z]).{6,20}$/"
    

    If the min and max condition is not required then remove .{6, 16}

    • 6 is minimum character limit
    • 20 is maximum character limit
    • ?= means match expression

提交回复
热议问题