Reputation: 250
I'm using 1000hz bootstrap validator to validate an email input and I can't get to escape the '@' character in my regular expression@
. Does anyone has an idea?
I tried @@, @('@') or even hexadecimal code (@). The hexadecimal was working fine until I updated Google Chrome to V53 and now it isn't valid anymore
Here's my input:
<input type="text" pattern="^[a-zA-Z0-9\.\_%+-]+@[a-zA-Z0-9\.\-]+\.[a-zA-Z]{2,4}" required data-error="Enter a valid email address" name="contractor-email" class="form-control" placeholder="e.g. [email protected]" />
Additionally, Chrome throws the following error message: validator.min.js:94 Pattern attribute value ^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+.[a-zA-Z]{2,4} is not a valid regular expression: Uncaught SyntaxError: Invalid regular expression: /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+.[a-zA-Z]{2,4}/: Invalid escape
Thanks in advance.
Upvotes: 0
Views: 641
Reputation: 250
So it turns out that the error wasn't from the '@' symbol but about the way I escaped the characters in the first element of my regex. The following regex works: ^[a-zA-Z0-9%+-\._]+@[a-zA-Z0-9\.\-]+\.[a-zA-Z]{2,4}
.
Thanks for the ones who helped.
Upvotes: 0
Reputation: 31
I don't know if it is the best practice, but use @("@") works
Upvotes: 1