I’m using the ASP.NET RegularExpressionValidator
I need a regular expression to keep users who fill out a form from using all caps.
For example, if they write their name:
Bob JONES or BOB JONES or BOB JOnes or whatever, it will not match.
I am able to match all caps with this regular expression:
[A-Z]{2,10}
But the RegularExpressionValidator requires me to match valid text, not invalid text.
If your goal is to have each word have no more than 1 capital letter in a row at a time, and assuming it’s okay to restrict to ASCII letters, try something like this:
In other words, the string must be entirely composed of either lowercase letters, or uppercase letters not followed by another uppercase letter.
This works for single words. For multiple words (like a full name, first and last), simply add a space to the alternation:
(Edited to allow apostrophe and hyphen punctuation)