What was asked for
Instead of "^[a-zA-Z][ ]*$" you want "^[a-zA-Z ]*$" . There are several answers that refer to \s , but you do not want them because they give you another white space, such as tabs.
Additional General Examples
On the side of the note, there are first names and last names containing hypens, for example Mary-Ann for a first or hyphen last name, for example Jones-Garcia . There are also names that have periods, such as St. Marc St. Marc . Finally, you have ' in some names, such as O'Donnel .
Side note
From a legal point of view, you can change your name Little Bobby Drop tables ... or include other random characters ... but I'm not sure how many systems are really suitable for such things.
If you need a general case (around the world), then do not limit the fields to any type of character, since you can have names in Greek letters, Cyrillic letters, Chinese letters, etc. There are also asymmetric English characters and other things like German umlaut.
If you are worried about SQL injection, use parameterized queries instead of dynamic queries.
Recommended Solution
If you are only worried about English letters and want to use a regular expression that processes the above examples, you can use "^[a-zA-Z \-\.\']*$"
source share