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

前端 未结 30 3734
伪装坚强ぢ
伪装坚强ぢ 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

提交回复
热议问题