regexp for checking the full name
Solution 1:
Does ^[a-z]([-']?[a-z]+)*( [a-z]([-']?[a-z]+)*)+$
work for you?
[a-z]
ensures that a name always starts with a letter, then [-']?[a-z]+
allows for a seperating character as long as it's followed by at least another letter. *
allows for any number of these parts.
The second half, ( [a-z]([-']?[a-z]+)*)
matches a space followed by another name of the same pattern. +
makes sure at least one additional name is present, but allows for more. ({1,2}
could be used if you want to allow only two or three part names.
Solution 2:
Simpler version
/^([\w]{3,})+\s+([\w\s]{3,})+$/i
([\w]{3,}) the first name should contain only letters and of length 3 or more
+\s the first name should be followed by a space
+([\w\s]{3,})+ the second name should contain only letters of length 3 or more and can be followed by other names or not
/i ignores the case of the letters. Can be uppercase or lowercase letters
Solution 3:
/^[a-zA-Z]+(([',. -][a-zA-Z ])?[a-zA-Z]*)*$/g