Either I'm having a really dim Friday, or something strange is going
on. I'm trying to add a method to the Validator plugin, using the
following regex:
/^[a-z0-9-.,()'%$£&"*\s]+$/
So I've added this into the "additional methods" JS file:
jQuery.validator.addMethod("lettersnumberandadvancedpunc", function
(value, element) {
console.log(value + " = " + /^[a-z0-9-.,()'%$£&"*\s]+$/i.test
(value));
return this.optional(element) || /^[a-z0-9-.,()'%$£&"*\s]+$/i.test
(value);
}, "Letters and punctuation only please");
Which, given a test input of, say, "My £2 hat", results in the
validation error being displayed and "My £2 hat = false" being written
to the console.
But... unless I'm missing something, that regex is fine and should
pass that string. Certainly in a test page that I created, it seems to
work:
$(document).ready(function(){
$('#btnTest').click(function(){
console.log($('#txtWTF').val() + " = " + /^[a-z0-9-.,()'%$£&"*\s]+$/
i.test($('#txtWTF').val()));
});
});
So what's going on? Why does my regex seem to be working elsewhere,
but not within the Validator plugin?