John_Nil
John_Nil

Reputation: 135

Issue with Jquery Validation for Name ( Characters only )

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

Answers (2)

Fewster
Fewster

Reputation: 100

Agree with M42:

\w matches any alphanumerical character (word characters) including underscore (short for [a-zA-Z0-9_]).

Regex to match only letters

Upvotes: 0

Toto
Toto

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

Related Questions