I need to validate the last name field on a form and have spent the last 3 hours reading tutorials and docs on using preg_match, but I just can't get my head wrapped around it.
I need to validate the field as follows:
1 or more upper or lower case letter
followed by
(0 or 1) hyphens OR spaces
followed by
(1 or more) upper or lower case letters if there is a hyphen OR space
In other words, zeta-jones, zeta jones, and Zeta Jones are all OK, but 5Zeta-jones, Zeta--jones, zeta-Jone9s, -jones, and zeta- are not.
The best I've been able to come with up is:
/+[^a-zA-Z](-|:space:){0,1}[^a-zA-Z]+/
and that is not working. In fact, I suspect I'm probably not even close. Any help anyone can give me in understanding this would be appreciated.