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

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

    I've actually just copied the first answer here and turned it into a more ux-convenient regex which needs one upper, one lower and at least 8 chars but accepts everything "in between".

    This one is an example-regex which requires

    1. at least 8 characters length
    2. at least one lowercase letter
    3. at least one uppercase letter

    IMPORTANT: This regex will also except all other characters e.g. numbers, special characters like $,#,! etc. - as long as the rules 1. to 3. match the input string

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

    Mind the "." alomst at the end of the regex. This will match almost any (and afaik any readable) character

提交回复
热议问题