1

Unable to check <input pattern='/^[a-zA-Zà-úÀ-Ú0-9äöüÄÖÜß@\s+-_.,{}[]()#']+$/'> because the pattern is not a valid regexp: invalid identity escape in regular expression

First Try: <br />
<input type="text" pattern="/^[a-zA-Zà-úÀ-Ú0-9äöüÄÖÜß@\s\+\-\_\.\,\{\}\[\]\(\)\#\']+$/">
<br />
Second Try: <br />
<input type="text" pattern="[a-zA-Zà-úÀ-Ú0-9äöüÄÖÜß@\s\+\-\_\.\,\{\}\[\]\(\)\#\']+">

1

1 Answer 1

1

Quoting MDN on the pattern attribute:

... No forward slashes should be specified around the pattern text.

The forward slashes are JavaScript syntax for regular expression literals.

Quoting from the same page:

... the 'u' flag is specified when compiling the regular expression, so that the pattern is treated as a sequence of Unicode code points, instead of as ASCII.

And quoting MDN's Guide Regular expressions:

  • Unicode regular expressions do not support so-called "identity escapes"; that is, patterns where an escaping backslash is not needed and effectively ignored. ...

This means only required character escapes are valid.

You should also be aware that ... (quoting from the same page)

  • The - character is interpreted differently within character classes. In particular, for Unicode regular expressions, - is interpreted as a literal - (and not as part of a range) only if it appears at the start or end of the character class.

In conclusion, your first pattern in fixed could look like this:

<input type="text" pattern="^[a-zA-Zà-úÀ-Ú0-9äöüÄÖÜß@\s+\-_\.,\{\}\[\]\(\)#']+$">

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.