I would like to develop a RegEx that can enforce a typical Forename format that enforces the below:
For example the following names would be fine: [John, Jean-Pierre, Smith.Rowe, Harry Smith]
But the following names would not be allowed [john, Jean--Pierre, Smith.-Rowe, Harry Smith (two spaces between names)]
Can anyone assist?
Below regex may help.
Lower case, upper case matches can be matched with [A-Z]
and [a-b]
.
Consecutive punctuations, can be matched with lookaround assertions.
^[A-Z](?:[a-zA-Z]|(?:(?<![ .'-])[ .'-](?![ .'-])))*[a-z]$