I've been using the jQuery form validator, but I can't seem to figure out how to trigger it by class. Take this example:
$("#myform").validate({
开发者_如何学Python rules: {
field: {
required: true,
date: true
}
}
});
Where field
it is expecting the name of the particular input. But, what if I have the following:
<input class="date".... />
How can I tell the validator to validate all inputs with a "date" class as a date?
jQuery.validator.addClassRules({
date: {
required: true,
date: true,
},
})
Just supplying the input with a class that matches one of the validation methods is sufficient to have the plugin validate that input using the method. If this isn't working for you, then I'd use Firefox/Firebug to check to make sure that you don't have some javascript errors that are causing the plugin not to run.
精彩评论