问题
I am using the jQuery Validation Plugin. Is there any way to get the type of error from the jQuery form validation? For example,
$('registration-form').validate({
rules: {
email: {
required: true,
email: true
}
},
messages: {
email: {
required: "This is a required field.",
email: "This is not a valid email address"
}
},
errorPlacement: function(error, element) {
error.appendTo(element.parent());
}
});
I would like to place only the error message generated from a "required" error inside a "div" somewhere on the html page rather than appending it to "element.parent()". If I can get the error type, e.g. "required" or "email" error, I can write the code to do this.
Any help is appreciated! Thanks!
aobs
回答1:
You may edit plugin easily. You can add one more parameter for each validation(see the regexes) to identify which one is caught.
来源:https://stackoverflow.com/questions/12075804/can-we-get-the-jquery-validate-error-type