我需要在单击 div 按钮时触发此验证。如果验证成功,我希望它提醒“很好”。
不幸的是,尽管验证会触发并检查所有规则,但如果必填字段为空,它不会出错。其他任何检查都会出错。
最后,如果我正确填写字段并单击按钮,则没有任何反应。
JS:
$(document).ready(function() {
// Submit prompted password reset
$("#passwordResetButton").click(function() {
$("#passwordResetForm").validate({
rules: {
password: { required: true, minlength: 8, maxlength: 40, remote: { url: "/ajax/isPasswordOK", data: { product: function() { return $("#password").val(); } } } },
confirmPassword: { required: true, equalTo: "#password" },
},
messages: {
password: { required: "Please enter a password", minlength: "Password must be at least 8 characters long", remote: "Password should contain: <li>At least one upper case character <li>At least one lower case character <li>At least one number <li>And may not contain any of the following: \\;-\")(&*='|$" },
confirmPassword: { required: "Please confirm your password", equalTo: "The passwords do not match" },
},
onkeyup: false, //turn off auto validate whilst typing
onblur: true,
afterValidation: function() {
alert('is good');
}
});
});
});
HTML:
<form id="passwordResetForm" style="width: 480px; margin: auto;">
<div class="row"><p class="lead">Let's reset that password</p></div>
<div class="row">
<div class="small-8 large-4 columns"><label>New Password:</label></div>
<div class="small-12 large-6 columns"><input name="password" id="password" type="password" size="20"/></div>
</div>
<div class="row">
<div class="small-8 large-4 columns"><label>Confirm Password:</label></div>
<div class="small-12 large-6 columns"><input name="confirmPassword" id="confirmPassword" type="password" size="20"/></div>
</div>
<div class="row">
<div class="large-offset-10 small-3 large-1 columns">
<div id="passwordResetButton" class="small button">Submit</div>
</div>
</div>
</form>