Is there possibility to add rules by wildcard? I think it’s not possible to set rules like this…
$("#form").validate({
// errorLabelContainer: $("div#error"),
errorElement: "p",
errorClass: "form-error",
rules: {
$("input[name*='x.child']"): {
required: true,
minlength: 5
}
}
});
Use the built-in
rules()method to add rules. See documentation.Note: You must call this method after you call
.validate().jsFiddle DEMO
This method can also be very useful when you are dynamically adding fields to your form.
The following to combine with custom
messages:. Note that the format is slightly different than when adding rules as options within.validate()…As mentioned elsewhere, you can also create a
classand use like this…jsFiddle DEMO
HTML:
jQuery: