Reputation: 135
I'm having some trouble properly validating a name format with a predefined jquery validation tool ,
I want the name to accept characters only and i even used a correct regex but it is still accepting numbers .
I'm using this script : http://jqueryvalidation.org/
This is what i added basically :
names: function(value, element) {
return this.optional(element) || /^\w+$/.test(value);
},
FULL JQUERY FILE :
file 1 : http://jsfiddle.net/EjSbd/ (script.js)
file 2 : http://jsfiddle.net/qM4Uz/ (jquery.validate.js)
full : http://jsfiddle.net/EjSbd/ ( doesn't compile tho )
Upvotes: 2
Views: 565
Reputation: 100
Agree with M42:
\w matches any alphanumerical character (word characters) including underscore (short for [a-zA-Z0-9_]).
Upvotes: 0
Reputation: 91375
I far as I understand, you want letters only, so:
names: function(value, element) {
return this.optional(element) || /^[a-zA-Z]+$/.test(value);
},
Upvotes: 2