RegEx to validate card holder name in ASP C#

asp.net, c#, regex

Solution

I just want it to accept alphabets in 1, 2 or 3 words with singe space in between them.

Try with following regex.

Regex: `^((?:[A-Za-z]+ ?){1,3})$`

Explanation: Atleast one character from character class `[A-Za-z]` followed by optional space. `{1,3}` ensures it's repeated atleast 1 and atmost 3 times.

Regex101 Demo

C# demo on Ideone

Problem

Trying to validate card holder name in my website. I tried the following regex ``` ^([a-z]+[,.]?[ ]?|[a-z]+['-]?)+$ ``` But it dosent validate against names like ``` JOHN DOE LOREM IPSUM ETC NAMES ``` I just want it to accept alphabets in 1, 2 or 3 words with singe space in between them. Example: ``` FIRST MIDDLE LAST FIRST LAST FIRST ```

Original source