I have to allow user to enter only 3 special characters in the email address and restrict them from entering any other special characters.
Below are the special characters
- hyphen
_ underscore
' apostrophe
The regular expression I am using is "\w+[-+.'_]*(\w+)*[\w]@\w+([-.]\w+)*\.\w+([-.]\w+)*"However this is failing when user is entering an email in the format
test-test'[email protected].
I think the combination of - and ' is not being allowed in the above expression.
Please help to resolve the issue.
Thanks.

VulpesRank #55 · 29.2K reputationPosted Feb 14, 2014, 1:25 AM EST
"^[\w'-]+\.?[\w'-]+@\w+[\w.-]+\w+$"
Note that \w already includes an _ and is equivalent to a-zA-Z0-9_
AFAIK domain names can contain underscores but not apostrophes. They can contain hyphens and dots but can't begin or end with them.
Resmi Satish112 reputationPosted Feb 23, 2014, 7:58 PM EST