JF0001
JF0001

Reputation: 839

Input Field accepting any Characters, ignoring Regular Expression

I have the following regular expression for an input field, which was validated as correct:

<input type='text' name='email' pattern="[/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/]" />

However, my field is accepting any string, ignoring the regex. I am working in Vue.js. What am I missing?

Please note that the Regex was taken from here.

Upvotes: 2

Views: 1261

Answers (1)

Ryszard Czech
Ryszard Czech

Reputation: 18631

Use

pattern="^\w+([.-]\w+)*@\w+([.-]\w+)*(\.\w{2,4})+$"

The brackets and slashes are not part of the pattern and must be removed.

Mind that special characters lose their special meaning inside brackets, hence use [.-] instead of [\.-].

Upvotes: 3

Related Questions