高洛峰2017-04-18 09:09:48
(?!^\d+$)不能全是数字
(?!^[a-zA-Z]+$)不能全是字母
(?!^[_#@]+$)不能全是符号(这里只列出了部分符号,可自己增加,有的符号可能需要转义)
.{8,}长度不能少于8位
合起来就是
(?!^\d+$)(?!^[a-zA-Z]+$)(?!^[_#@]+$).{8,}
巴扎黑2017-04-18 09:09:48
After verification, @BodhiXuguang’s answer is incorrect. For example, hello123
就能匹配, 但并不满足要求. 而且
8 spaces can also be matched, but it does not meet the requirements, and you cannot add all special symbols.
Although (?=[a-zA-Z0-9_#@]+)
can be added to ensure that the password will not contain special symbols other than those specified, there is still no guarantee that it must have three symbols.
Not all numbers/letters/special symbols, the result is as long as it contains more than 2 types of symbols.
In fact, this is not a regular question, please refer to similar questions
伊谢尔伦2017-04-18 09:09:48
@BodhiXuguang’s idea is right. Just replace the negative lookahead with a positive lookahead and make some adjustments.
(?=.d.)(?=.[a-zA-Z].)(?=.[_#@].).{8,}
迷茫2017-04-18 09:09:48
I think this problem should not be solved with regular expressions. Each tool has its own scenarios that are very suitable for use. I think it is not suitable to use regular expressions to solve it in your scenario. Use a simple if statement to judge. The implementation is simple and the readability is very good. Why must we use regular expressions? ?