I wrote a Regex to match first / last name for a registration form in my web site.
The requirements are:
- Up to 44 chars
-or'are acceptable- One space is acceptable within the names
- Unicode is not required
Is there any way to make my expression shorter?
^[a-zA-Z]{2,12}['-]?[a-zA-Z]{1,10}\s?[a-zA-Z]{2,12}['-]?[a-zA-Z]{1,10}$
Is it too much restrictions for a name field?
First with your regex the response is up to 47 chars : 12+1+10+1+12+1+10.
I think the best way for you is to allow 44 chars from letters, coma, minus or white space.
You can force the first char to be a letter :