How to run jQuery form validation by class?

I am using the jQuery form validator, but I cannot figure out how to run it in a class. Take this example:

$("#myform").validate({
  rules: {
    field: {
      required: true,
      date: true
    }
  }
});

Where fieldhe expects the name of a particular input. But, if I have the following:

<input class="date".... />

How can I tell the validator to check all inputs with a date class as a date?

+3
source share
2 answers
jQuery.validator.addClassRules({
    date: {
        required: true,
        date: true,
    },
})
+4
source

, , , , . , Firefox/Firebug , javascript, - .

+2

Source: https://habr.com/ru/post/1739293/


All Articles