1

I wrote a custom validator for jquery validator plugin .

Problem is, the custom validator I wrote is throwing error for anything I input. If I input plain text, it will still show error message.

Smokey
  • 1,857
  • 6
  • 33
  • 63

1 Answers1

1

Since it's a validator your function should return false if the value matches the regex and true if not:

$.validator.addMethod('noHTMLallowed', function(value) {
  return !/<(.|\n)*?>/.test(value);
}, 'It contains HTML tags');
Kosh
  • 16,966
  • 2
  • 19
  • 34