I have a RegularExpressionValidator where the only valid input is 8 characters long and consists of the letters MP followed by six digits. At the moment I have the following regex which does work
^(MP|mp|Mp|mP)[0-9]{6}$
but it feels a bit hacky. I'd like to be able to specify that the MP can be any combination of upper and lower case without having to list the available combinations.
Thanks,
David
You can do this when you define Regex object
Regex exp = new Regex(
@"^mp[0-9]{6}$",
RegexOptions.IgnoreCase);
Alternatively you can use ^(?i)mp[0-9]{6}$
syntax, which would make just specific bit of regex case-insensitive. But I would personally use the first option (it is easier to read).
For details see documentation on msnd.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With