【发布时间】:2017-08-08 03:12:55
【问题描述】:
我用了jquery.validate,我想在用户输入时验证密码但它不起作用。
检查 pwcheck 密码不起作用。请看看我怎么了?
if (jQuery().validate) {
$.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
});
$('#myform').validate({
rules: {
forename: {
required: true,
maxlength: 300
},
surname: {
required: true,
maxlength: 300
},
password: {
required: true,
minlength: 8,
maxlength: 300
},
password_repeat: {
required: true,
minlength: 8,
maxlength: 300,
equalTo: '#password'
}
},
messages: {
password: {
pwcheck: "Das Passwort entspricht nicht den Kriterien!",
}
},
submitHandler: function(form) {
if (grecaptcha.getResponse()) {
form.submit();
} else {
alert('Please complete the reCaptcha to proceed');
}
}
});
});
【问题讨论】:
-
您创建了名为
pwcheck的新规则,但您没有在任何地方使用它。 -
我解决了我的问题。原因是因为我没有添加
pwcheck: true
标签: jquery regex jquery-validate