在 ASP.NET RegularExpressionValidator 中使正则表达式不区分大小写 [英] Make regular expression case insensitive in ASP.NET RegularExpressionValidator
问题描述
给定这个正则表达式:"^[0-9]*s*(lbs|kg|kgs)$"
如何让它不区分大小写?我正在尝试在 .net 正则表达式验证器中使用它,因此我需要在模式中指定不区分大小写.
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.
我无法以编程方式使用 RegexOptions,因为我在 RegularExpressionValidator 中指定了正则表达式
推荐答案
我发现了.
区分大小写:^[0-9]s(lbs|kg|kgs)$
不区分大小写:(?i:^[0-9]s(lbs|kg|kgs)$)
我相信这是特定于正则表达式的 .NET 实现的.因此,如果您在 RegularExpressionValidator 中使用它,您必须关闭客户端验证,因为 javascript 正则表达式解析器将无法识别 ?i
标记.
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.
这篇关于在 ASP.NET RegularExpressionValidator 中使正则表达式不区分大小写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!