Reputation: 839
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
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