我使用jquery.validate
,我想在用戶輸入時驗證密碼,但它不起作用。jquery.validate pwcheck密碼不起作用
檢查pwcheck密碼不起作用。請看我有什麼問題嗎?
if (jQuery().validate) {
$.validator.addMethod("pwcheck", function(value) {
return /^[A-Za-z0-9\d=!\[email protected]_*]*$/.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'新規則,但你不要在任何地方使用它。 – Sparky
我解決了我的問題。原因,因爲我沒有添加'pwcheck:true' –