正在检查密码强度

Checking for password strength

本文关键字:密码 检查      更新时间:2023-09-26

有人能告诉我密码字段validation出了什么问题吗?我正在检查密码strength,无论我输入了什么,它总是说"密码必须至少包含一个数字和一个字符"

jQuery.validator.addMethod("pwcheck", function(value) {
   return /^[A-Za-z0-9!@#$%^&*()_]$/.test(value) // consists of only these
       && /[a-z]/.test(value) // has a lowercase letter
       && /'d/.test(value) // has a digit
}, "password must contain atleast one number and one character");

我想检查我的密码字段是否允许至少一个数字、一个字符和任意数量的特殊字符/数字/字符

您的第一个正则表达式表示它只能有一个字符。。。所以把它改成

/^[A-Za-z0-9!@#$%^&*()_]+$/.test(value)// add + to indicate one or more instances of the set

演示:Fiddle

试试这个,

jQuery.validator.addMethod("pwcheck", function(value) {
   return /^[A-Za-z0-9!@#$%^&*()_]+$/.test(value)&& /[a-z]/.test(value) 
   && /'d/.test(value) ;
}, "password must contain atleast one number and one character");