I am trying to create a regular expression in JavaScript which matches names, but excludes numbers.
What I have so far matches most names, but I cannot get it to exclude numbers on the second names. The regex I have is:-
/^A-Z+sA-Z([A-Z]|[a-z]+)(([A-Z]|-|[a-z])|([A-Z][a-z]+))
Which matches:-
John Smith
Kevin O’Kief
Kevin John-Smith
Kevin-Smith Connor1
but does not match (correctly):-
JohnO’Rourke
Jo1n O’Rourke
1Terry
However I cannot for the life of me get it to not match “Kevin-Smith Connor1” which has a number in it. I’m sure its something really simple but I just cannot see it.
I tried [^0-9] in various places in the second part of the regex, but cannot get it to not match Kevin-Smith Connor1
S F is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.