Reputation: 97
I have a situation in which email domain need to pass below scenarios
Domain:
Not Accepted subdomain
Accepted
Example:
Email- [email protected]
Username - foobar
Domain - mahi.co.in
var emailIdExp = ^[A-Za-z0-9._-]+@([A-Za-z0-9-]+\.)*[A-Za-z0-9-]+\.[A-Za-z0-9-]{2,}$
Upvotes: 0
Views: 755
Reputation: 392
You can try with:
^[\w.-]+@[A-Za-z0-9]+([-]?[A-Za-z0-9]+)+([\.][A-Za-z0-9]+([-]?[A-Za-z0-9]+)+)+$
The above regex is updated here : https://regex101.com/r/7P4XWM/3
Hope it helps :)
Upvotes: 1
Reputation: 4937
You can try with that regex:
^[\w-_\.]+@\w+(-\w+)*(\.\w+(-\w+)*)+$
Example: https://regex101.com/r/7P4XWM/1
With that, the following condition is not fulfilled, though:
Upvotes: 1