I am getting the below console warning for this regex pattern:
^[a-zA-Z0-9+_.-]+@[a-zA-Z0-9]+\\.[a-zA-Z0-9]+$
Pattern attribute value
^[a-zA-Z0-9+_.-]+@[a-zA-Z0-9]+\.[a-zA-Z0-9]+$is valid with the RegExpuflag, but not with thevflag:
Uncaught SyntaxError: Invalid regular expression:/^[a-zA-Z0-9+_.-]+@[a-zA-Z0-9]+\.[a-zA-Z0-9]+$/v:Invalid character in character class.
I cannot see how to create a valid regex pattern for this warning. Please, could somebody explain the error and how to resolve it?
I tried looking at documentation, but could not see how to make it valid for the v flag
The issue is that the newly introduced
vflag inside HTMLpatternattribute is used automatically when compiling a RegExp objectThe value provided to a
patternattribute is converted into a regular expression with thevflag for unicode sets.The
<input>patternattribute reference states:The
/vflag applies even more restrictions to escaping rules. Since it allows character class subtraction and intersection, the literal-at the end of a character class cannot be left unescaped.So, if you use the
uflag, there is no such a restriction, with thevflag, it is in place. Cf.So, always escape literal hyphens inside character classes in ECMAScript patterns.
Here are more details on which patterns are now considered invalid: