I have the following validation code wherein it filters only alpha numeric + white space text… But upon testing two alpha numeric words with whitespace, it fails…
$.validator.addMethod("alphaNumeric", function(value, element) {
$(element).val(value.replace(/^\s+|\s+$/g,''));
return /^[a-zA-Z0-9 ]*$/.test(value);
}, " AlphaNumeric Only!");
What is wrong with my code?
you change the input value but its not the value you are checking on your validation:
I don´t know of the replacement/trim method should be in a validation rule. But this should work.