3 回答

TA贡献1719条经验 获得超6个赞
如果您需要一个正则表达式,请尝试:
(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*\W)
一个简短的解释:
(?=.*[a-z]) // use positive look ahead to see if at least one lower case letter exists
(?=.*[A-Z]) // use positive look ahead to see if at least one upper case letter exists
(?=.*\d) // use positive look ahead to see if at least one digit exists
(?=.*\W]) // use positive look ahead to see if at least one non-word character exists
我同意SilentGhost,\W可能有点宽泛。我用这样的字符集替换它:( [-+_!@#$%^&*.,?]当然可以添加更多!)

TA贡献1817条经验 获得超6个赞
Bart Kiers,你的正则表达式有几个问题。最好的方法是:
(.*[a-z].*) // For lower cases
(.*[A-Z].*) // For upper cases
(.*\d.*) // For digits
无论是在开头,结尾还是在中间,你都会以这种方式进行搜索。你有我复杂的密码有很多麻烦。
- 3 回答
- 0 关注
- 614 浏览
添加回答
举报