On the system I'm working on, regular expressions are used to provide a specific input format for WPF text fields.
Behavior receives a Regex object and manages entered characters and allows only valid ones. ( similar to this article )
However, there is one exception. When only uppercase characters are accepted, the characters entered must be automatically converted to uppercase instead of being rejected.
My question is:
How to elegantly determine that the regex provided in Regex will only accept upper case? Is the only way to check the lowercase string string and then the uppercase string on it? Example:
if (Regex.IsMatch("THIS SHOULD PASS") && !Regex.IsMatch("this should fail")
{
// logic to convert lower case to upper case.
}
Louis source
share