I am using the following validation rules for my form. I need to display one common error message for all the validations. I have grouped the controls but can not pass the message.
$(function() {
jQuery.validator.addMethod("lettersonly", function(value, element) {
r开发者_JS百科eturn this.optional(element) || /^[a-z]+$/i.test(value);
}, "Letters only please");
$(".form").validate({
errorLabelContainer: "#errorMessages",
groups: {
username: "name email lName zip"
},
rules: {
name:{
required: true,
lettersonly: true
},
email: {
required: true,
email: true
},
lName: "required",
zip: "required"
},
messages: {
username:"Sorry friend, your vote was not processed because you forgot to enter the required information. Enter it now."
}
});
});
function(){
bValid = bValid && Function1toValidate($('#txtTitle'));
bValid = bValid && Function2toValidate($('#txtEmail'));
if (bValid)
{
proceed with the procedure
}
else
{
your error message
}
}
//those validate functions code it here
Function1toValidate()
{}
Function2toValidate()
{}
精彩评论