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.
VulpesPosted Feb 14, 2014, 6:25 AM
"^[\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 SatishPosted Feb 24, 2014, 12:58 AM