Click here to Skip to main content
15,907,183 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to validate two different domain email addresses using Regular Expression.
we have two domains e.g and

For single domain it is working as:

[RegularExpression(@"^[a-zA-Z0-9._%+-]+(@mydomain\.com)$", ErrorMessage = "Registration limited to mydomain")]

How can I add both of the domains, can anyone assist?
Updated 6-May-15 18:27pm

You don't need regular expression. This validation is already done in the class System.Uri, by its constructor. You can find an example here:[^].

Also, you should handle and catch exceptions, as the string might not be valid. For the exceptions which can be thrown, please see:[^].

If you don't expect "mailto:" in the test string, you have to prefix your input string with it. You can take it from System.Uri.UriSchemeMailto.

Put it all together to create the validation. As an additional bonus, you will get not just true/false answer, but, in case of successful validation, the instance of Systen.Uri, which is much more useful/informative than raw string.

Share this answer
Your Regex should be like

Share this answer
Mostafa Asaduzzaman 7-May-15 0:43am    
Appreciate your response @Suvabrata
Suvabrata Roy 7-May-15 1:00am    
[no name] 7-May-15 0:50am    
Good Answer +5
Suvabrata Roy 7-May-15 1:01am    
To validate email using regular expression

function validate(your_email)
var regilar_exp= /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;

return regilar_exp.test(email);
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900