0

I am trying to add a validation rule for jQuery validate

$validator.addMethod('footer-email', function (value) {
  if (value == ''){
    return true;
  }
}, '');

Where footer-email is class selector. Is there a way I can use a ID selector instead?

Shiladitya
  • 12,003
  • 15
  • 25
  • 38
soum
  • 1,131
  • 3
  • 20
  • 47
  • First parameter inside `.addMethod()` is the "name" of this new rule, NOT a class, although you can use the name of the rule as a class to declare the rule on a field. – Sparky Dec 12 '17 at 16:27

1 Answers1

0

From the docs, it looks like the first parameter is the name of validation method you are adding, not the element selector. You would later use

$validator.addMethod('valid_email', function(value) { ... });
$('#my_form').validate({
    rules: {
        my_field: {
            valid_email: true
        }
    }
})

I don't think it's powerful enough to support custom selectors. See related question: jQuery validate plugin : custom rules with dynamic element id .

James Lim
  • 12,915
  • 4
  • 40
  • 65