简体   繁体   中英

Javascript case insensitive regex without flags

Situation:

MVC+DevExpress .NET

Client-side validation based on server-side attributes (like [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

var regEx = new RegExp(this.pattern);

.NET-style inline modifiers, like (?i) return "Unexpected quantifier" error.

Ugly alternative is writing something like ^[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. But, you could get the original regex source using the .source property and then create a new RegExp object with the newly desired flags.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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