2

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 )

ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257
John_Nil
  • 165
  • 2
  • 4
  • 17

2 Answers2

2

I far as I understand, you want letters only, so:

names: function(value, element) {
            return this.optional(element) || /^[a-zA-Z]+$/.test(value);

    },
Toto
  • 89,455
  • 62
  • 89
  • 125
  • Worked perfectly - thanks . Need to learn regex again - i thought /w did not include numbers – John_Nil Feb 04 '14 at 17:47
  • @John_Nil: You're welcome. Here is an interesting site about regex: http://www.regular-expressions.info/ – Toto Feb 04 '14 at 17:50
0

Agree with M42:

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

Regex to match only letters

Community
  • 1
  • 1
Fewster
  • 100
  • 1
  • 1
  • 10