Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make regular expression case insensitive in ASP.NET RegularExpressionValidator

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, so I need to specify case insensitivity in the pattern.

I can not use the RegexOptions programatically because I am specifying the regular expression in a RegularExpressionValidator

like image 498
Jeremy Avatar asked Apr 14 '10 21:04

Jeremy


1 Answers

I found out.

Case sensitive: ^[0-9]\s(lbs|kg|kgs)$

Case insensitive: (?i:^[0-9]\s(lbs|kg|kgs)$)

I believe that this is specific to the .NET implementation of regular expressions. So if you use this in the RegularExpressionValidator you have to turn off client side validation because the javascript regex parser will not recognize the ?i token.

like image 94
Jeremy Avatar answered Oct 11 '22 04:10

Jeremy