I'm using http://bassistance.de/jquery-plugins/jquery-plugin-validation/ to validate my form. Unfortunately, there is no text only method. So I tried to write my own:
$(document).ready(function(){
$("#staffedit").validate(
{
rules: {
editDisplayName: {
textonly: true,
required: true
}
}}
);
jQuery.validator.addMethod(
"textonly",
function(value, element)
{console.log('textonly called.');
console.log(/[-.\w\s]/.test(value));
return this.optional(element) || /[-.\w\s]/.test(value);
},
jQuery.format("Please only enter letters, spaces, periods, or hyphens.")
);
});
The method gets called, since my console.log function does output to the console at the appropriate times. What I don't understand, is why I can still put $ or * in the input field. I can put anything in there, and it still gets evaluated as valid.
I used http://regexpal.com/ to test the regex, and it works fine there.
So, how do I get the plugin to only allow text, spaces, periods, and hyphens?
On a side note, I'd also like to allow characters with accents, like à, É, ā, or ô...