Take the 2-minute tour ×

Possible Duplicate:
What is the best regular expression for validating email addresses?

I'm using a form which ask for email address. I used regular expression for it as


But it is not working fine for some of my test email id like


Any one provide me regular expression for the email validation in asp.net or can i use any other method for it.

Please give your suggestions.

share|improve this question

marked as duplicate by Bobby, ho1, Phil Ross, ChrisF, Aistina Sep 7 '10 at 9:27


As a rule of thumb: Think at least twice before using . in regular expressions. Note that ....@...... also matches your expression. –  Michael Sep 7 '10 at 9:26
@Michael: In that particular case it actually makes sense to have a rather loose validation. Actual email addresses follow highly complex rules and it usually is not worth the effort to create an overly complex (read erroneous) regular expression. For example, some major freemail providers don't allow the perfectly valid '+' character. Bam. –  Dirk Vollmar - 0xA3 Sep 7 '10 at 9:31
True, still, using . should only be done with caution and is, in this case, still wrong. IMHO, this validation is neither "too loose" nor "too strict" since the strings are neither a superset nor a subset of the real valid email addresses. It's just wrong. –  Michael Sep 7 '10 at 9:57

3 Answers 3

up vote 6 down vote accepted

Best to rely on the framework for this kind of stuff.

try {
    address = new MailAddress(address).Address;
} catch(FormatException) {
    //address is invalid
share|improve this answer
+1 Now that's an idea! –  Bobby Sep 7 '10 at 9:30
Though I'd say only if you're using .Net 4, I'm fairly sure earlier versions would fail on various types of valid email addresses. –  ho1 Sep 7 '10 at 9:37
I beg your pardon, but this snippet of code is OK since .NET 2 One has to catch the exception, though. [ msdn.microsoft.com/en-us/library/… ] –  Vinzz Sep 7 '10 at 9:46

I am using the following regular expression for my email validations (case insensitive):


I do not know about asp, but i think that you can use it like this.

share|improve this answer
share|improve this answer
