Reputation: 44303
I found this simple regexp (i know it's probably not perfect) somewhere online to validate an email address.
/^(?:\w+\.?)*\w+@(?:\w+\.)+\w+$/
The problem is, that this regexp doesn't allow for the following case:
[email protected]
[email protected]
Any ideas?
ps. I'm using this regexp within javascript.
Upvotes: 2
Views: 2767
Reputation: 4209
If you simply want to add hyphens you can change the regexp to:
/^(?:\w+[\-\.])*\w+@(?:\w+[\-\.])*\w+\.\w+$/
To add other special chars e.g. like underscore just put them in the first (not the second) pair of square brackets, i.e. change [\-\.]
to [\-\._]
.
Also have a look on this question and its anwer.
Upvotes: 5