Given this regular expression: \"^[0-9]*\\s*(lbs|kg|kgs)$\" how do I make it case insensitive? I am trying to use this in a .net regular expression validator,
Can we make Regex case-insensitive in C#? : Yes
Set option inline via (?i) pattern construct or via RegexOptions.IgnoreCase param
Can we make Regex case-insensitive in JavaScript? : Yes
Set flag via /pattern/flags syntax or the insensitive flag
/REGEX/i
(Aside) Can we make Regex case-insensitive in HTML5 Pattern Attribute? : No
As Chris R. Timmons points out on RegularExpressionValidator doesn't ignore case:
There is no property in the RegularExpressionValidator control that allows regex options to be set.
If your control does both client-side and server-side validation, the regex must use a subset of regular expression syntax that both JS and .NET can execute. In this case, to make a regex ignore case it is necessary to use a character class construct like
[a-zA-Z]to match both upper and lower case characters.If your validation is done on the server-side only, you can use the more powerful .NET regular expression syntax. In this case, you can place the
(?i)option at the beginning of the regex to tell it to ignore case.
So, if you want to use the out of the box validator, you're stuck with Geoff's solution of using character sets like this: [aA]