You can extend it and add your own rule.
jQuery.validator.addMethod("edu", function(value, element) {
// Make it work optionally OR
// Check the last 4 characters and ensure they match .edu
return (this.optional(element) || value.slice(-4) == ".edu");
}, "You must use a .edu email address");
$("#myform").validate({
rules: {
field: {
required: true,
email: true,
edu: true
}
}
});
Here is a jsfiddle showing how it all works together and how the errors cascade. Just press the button.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…