How to avoid RegEx, which generates an "unexpected quantifier" error in IE?

I am using asp.net and c #. I have a TextBox with validation controls with RegEx.

I use this code as confirmation.

ValidationExpression="^(?s)(.){4,128}$" 

But only in IE9 I get the error message: unexpected quantifier from the javascript section.

I probably need to escape my RegEx, but I don't know how to do this and what to avoid.

Could you help me with the sample code? Thanks

+4
source share
3 answers

Instead, write:

  ^([\s\S]){4,128}$ 

I suspect that (? S) is causing the error.

+5
source

Three problems: (1) JavaScript does not support built-in modifiers, such as (?s) , (2) there is no other way to pass modifiers in the ASP validator, and (3) none of these facts matter, t supports single-line mode. Most people use [\s\S] to match any-in-new characters in JavaScript expressions.

EDIT: Here's how it would look in your case:

 ValidationExpression="^[\s\S]{4,128}$" 

[\s\S] is a character class that matches any space character ( \s ) or any character that is not a space character — in other words, any character. The dot metacharacter ( . ) Matches any character except a newline. Most regular expression flavors (such as .NET) support Singleline or DOTALL mode, which also makes dot characters, but not JavaScript.

+2
source

JavaScript does not understand (?s) afaik, you can replace it instead . on [^] or [\s\S] .

For example: ^[^]{4,128}$

0
source

Source: https://habr.com/ru/post/1381311/


All Articles