开发者

How do I run jQuery form validation by class?

开发者 https://www.devze.com 2022-12-25 10:03 出处:网络
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:

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消