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

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

    I've found many problems here, so I made my own.

    Here it is in all it's glory, with tests:

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

    https://regex101.com/r/DCRR65/4/tests

    Things to look out for:

    1. doesn't use \w because that includes _, which I'm testing for.
    2. I've had lots of troubles matching symbols, without matching the end of the line.
    3. Doesn't specify symbols specifically, this is also because different locales may have different symbols on their keyboards that they may want to use.

提交回复
热议问题