tags:

views:

30

answers:

2

I would like to write a function to validate a full name input in a form with Javascript:

a single word will be ok, a string with some blank character among name surname, middle name too, but I do not want any digit.

Any suggestion?

+1  A: 

I would suggest not putting so much effort in validating data via JS. If a user has JS disabled, you will end up with some data you don't want on database.

Validate it via the server side.

Now, regards your question, I would try with regular expressions.

metrobalderas
A: 

There are several ways to write this, but, simply, the regular expression

/^[a-zA-Z ]+$/ 

should work for you. It will find any combination of alpha characters and spaces but no digits.

Robusto
You may also wish to add the apostrophe and hyphen between the brackets, since Irish and Italian names include the former (O'Donnell, D'Ambrosio) and some folks have hyphenated last names (Claude Levi-Strauss, Ima Page-Turner, etc.).
Robusto