我需要一个使用JavaScript进行密码验证的正则表达式,它应该在(* ^%$#@)和多个字母字符中包含至少一个数字和一个特殊字符符号。目前我正在使用下面的代码片段,它不起作用:
/^(?=(.*[a-zA-Z]{2}))(?=.*\d)(?=.*(\*))(?=.*(^))(?=.*(%))(?=.*(#))(?=.*($))(?=.*(@))$/
有人可以帮帮我吗?
答案 0 :(得分:0)
将所有要求排列为断言,然后匹配字符串
如果断言得到满足
(?i)^(?=(?:.*[a-z]){2})(?=.*\d)(?=.*[*^%$#@]).+$
(?i) # In line modifier - case insensitive
^ # BOS
(?= # Assert - at least 2 alpha's
(?: .* [a-z] ){2}
)
(?= .* \d ) # Assert - at least 1 numeric
(?= .* [*^%$#@] ) # Assert - at least 1 special
.+ # Match all here
$ # EOS