【问题标题】:Checking for password strength [duplicate]检查密码强度[重复]
【发布时间】:2014-10-26 16:03:38
【问题描述】:

谁能告诉我密码字段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");

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

【问题讨论】:

    标签: javascript jquery regex jquery-validate


    【解决方案1】:

    您的第一个正则表达式说它只能有一个字符...所以将其更改为

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

    演示:Fiddle

    【讨论】:

      【解决方案2】:

      试试这个,

      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");
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2010-11-26
        • 2012-06-16
        • 1970-01-01
        • 2013-06-10
        • 2013-05-18
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多