The point is that Chrome and Firefox already support ES6 regex specifications and support the Unicode mode by default.
Unicode patterns have stricter rules as to what characters can be escaped inside the pattern. See this reference:
IdentityEscape: In BMP patterns, many characters can be prefixed with a backslash and are interpreted as themselves (for example: if u
is not followed by four hexadecimal digits, it is interpreted as u
). In Unicode patterns that only works for the following characters (which frees up u
for Unicode code point escapes): ^
$
.
*
+
?
(
)
[
]
{
}
|
The same set of chars is referred to as SyntaxCharacter in the ES6 specs page.
So, you can only escape the -
inside the character class where it is considered a special character and to make it a literal you can escape it. Everywhere else it must not be escaped.
<form>
<input type="text" pattern=".*(d{3}-d{3}-d{2}-d{2}|d{3}-d{2}-d{2}-d{3}|d{10}).*">
<input type=Submit>
</form>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…