简体   繁体   English

Javascript不区分大小写的正则表达式,不带标志

[英]Javascript case insensitive regex without flags

Situation: 情况:

MVC+DevExpress .NET MVC + DevExpress .NET

Client-side validation based on server-side attributes (like [RegularExpression("^con|prn|aux$")] ) 基于服务器端属性的客户端验证(例如[RegularExpression(“ ^ con | prn | aux $”]]

Is there a way to make validation case-insensitive? 有没有办法使验证不区分大小写?

I cannot add i flag, because RegExp object is created inside DevExpress client-side code by 我无法添加i标志,因为RegExp对象是在DevExpress客户端代码中通过以下方式创建的:

var regEx = new RegExp(this.pattern); var regEx = new RegExp(this.pattern);

.NET-style inline modifiers, like (?i) return "Unexpected quantifier" error. .NET样式的内联修饰符,例如(?i)返回“意外量词”错误。

Ugly alternative is writing something like ^[Cc][Oo][Nn]|[Pp][Rr][Nn]|[Aa][Uu][Xx]$ 丑陋的替代方法是写类似^ [Cc] [Oo] [Nn] | [Pp] [Rr] [Nn] | [Aa] [Uu] [Xx] $

Once the javascript RegExp object has been created, you can't change the regular expression or the flags. 创建javascript RegExp对象后,您将无法更改正则表达式或标志。 But, you could get the original regex source using the .source property and then create a new RegExp object with the newly desired flags. 但是,您可以使用.source属性获取原始正则表达式源,然后使用新的所需标志创建一个新的RegExp对象。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM