Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to validate a name that consists of both first and surname?

Status
Not open for further replies.

slimjimscot

Programmer
Dec 6, 2003
4
GB
HI,

I am trying to find a regular expression that will validate a name entered in a form that consists of both a first name and a surname. In Larry Ullman's book he has an example for validating a first name:

eregi ("^([[:alpha:]]|-|')+$", $name)

But this doesn't work for me - I assume that is because it doesn't take into account that in my case there is a space between the first name and the surname (I want to keep it like that).

How do I alter the above regular expresion to all spaces so that it will validate my names ok?

Any help will be much appreciated.

Thanks,
Jim

 
Ok, I think I've figured it out; I needed to put another pipe (|) after the apostrophe and add a space:

^([[:alpha:]]|-|'| )+$

I hadn't realised that those pipe characters meant 'or'.

All the best,
Jim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top