jQuery Validate plugin - password check - minimum requirements - Regex

后端 未结 5 1397
感动是毒
感动是毒 2020-11-28 07:29

I\'ve got a little problem with my password-checker.

There\'s got a registration form with some fields. I use jQuery Validate plugin to validate user-inputs.

5条回答
  •  爱一瞬间的悲伤
    2020-11-28 08:21

    If I add (?=.*[a-z]) the whole code doesn't work anymore.

    Add it here:

    /^(?=.*[a-z])[A-Za-z0-9\d=!\-@._*]+$/
    

    However, it's much easier to do this without a lookahead:

    $.validator.addMethod("pwcheck", function(value) {
       return /^[A-Za-z0-9\d=!\-@._*]*$/.test(value) // consists of only these
           && /[a-z]/.test(value) // has a lowercase letter
           && /\d/.test(value) // has a digit
    });
    

提交回复
热议问题