Validate plugin: custom validator always returning alert message
I have created custom validation to make sure that the value being passed only contains letters. In the code below, I purposely put "abcde" to give it a basic test but the result is the same when I test it against the a real passed value. As the code sits right now, I DON'T expect see "letters only please" returned. By changing the test string to "ab56cde" I would expect to see it. The problem is, no matter what I change the string to I still get the alert message returned which I assume means that it's always returning true.
I have tried various solutions but they all return true. Any suggestions?
- $.validator.addMethod('limittext', function(value, element) {
- return "abcde".match(new RegExp("/[^a-z]/i"));
- },"letters only please");
- $("#casting").validate({
- ignore: 'input[type=hidden]',
- errorElement: "em",
- rules:
- {
- 'tag_list': { countrestrict: true, limittext: true }
- },