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.

Lonewolf
  • 1,751
  • 6
  • 29
  • 62

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
  • 15,805
  • 2
  • 17
  • 32