The task at hand is to validate the Textbox in asp.net for a valid email address.

We can attach a RegularExpressionValidator to the text box with the following regular expression:

<asp:RegularExpressionValidator ValidationExpression="^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$" ID="rxpEmail" runat="server"
ErrorMessage="Email Address is not valid" Text="*" Display="Static" ControlToValidate="txtEmail"></asp:RegularExpressionValidator>

UPDATES
Well i searched the net for the standards of a valid email id and i came across with a wonderful article at

I Knew How To Validate An Email Address Until I Read The RFC

It gives a an idea of what an exact RFC standard for the email id is.

I believe that we should follow validations which are quite obvious to the users and allow only standard email addresses.

kick it on DotNetKicks.com

Shout it

pimp it

Anky Goyal

I am MCPD certified in .NET and working on .NET technologies for past 3yrs. I am very passionate about the new features which get introduced in the technology. I am here to share the new features i get to know in the world of Microsoft. Follow me on twitter @ankygoyal LinkedIN@Ankit Goyal

More Posts - Website

18 Responses to Regular Expression for Email Address validation in C#


  1. JL
    Jun 06, 2009

    I don’t understand the right part of the regex.
    It would match:
    name1.name2@mail.123

    I don’t think tld can be numbers.


  2. David
    Jun 07, 2009

    “+” is also valid character.

    e.g.

    yourname+thispartgetsignored@gmail.com

    is equivalent to:

    yourname@gmail.com


    • Ankit Goyal
      Jun 08, 2009

      new info for me….
      have never tried this…i will work on it…
      thnkss david…


  3. Micah Burnett
    Jun 08, 2009

    I prefer a dumbed down the expression that catches most of the real-world problems instead of verifying every possible combination. The ultimate validation is when the mail server rejects the address…then you know for sure!

    Our Republic


    • Ankit Goyal
      Jun 08, 2009

      Micah u r rite as the ultimate validation for a email address is achieved when we ping the mail server for the specified email address…


  4. john
    Oct 29, 2009

    Hi, I could see one nice method here http://www.Tctcworld.com. if u need go through it..


  5. Craig
    Nov 06, 2009

    If you want to validate e-mail addresses by pinging their mail server just use EmailVerify.NET, a .NET component which can test e-mail syntactically, verify the DNS MX records for the each domain and connect to each mail server to check if the mailbox exists or not.

    It works like a charm!!
    There’s also a nice demo on their website: http://www.emailverify.net

    Hope this helps.


  6. Margish
    Feb 19, 2010

    This worked for my task
    [a-z]*\.*[a-z]*@[a-z]*\.[a-z]*


  7. Javin Paul
    Jan 06, 2011

    Does regular expression remains same across language e..g rregex in unix, regex in java , regex in perl

    are all they exactly same ?


  8. Jared
    Jul 31, 2011

    I wrote a regular expression for validating an email address that is quite short and quite accurate, but I am trying to get more feed back.

    Regular Expressions in C# (including a new comprehensive email pattern)
    http://www.rhyous.com/2010/06/15/regular-expressions-in-cincluding-a-new-comprehensive-email-pattern/

    I tried yours and it missed about 1/4th the emails in my list and so I thought maybe you could try mine and see if you get more accurate results or if mine has problems I don’t know about.


  9. Blanche Mccleaf
    Dec 14, 2011

    Howdy. Basically want to comment and express that I admired this post. I’ll be bookmarking your web-site and checking to see if you post any new ones. Thanks so much!


  10. Tonja Breyfogle
    Jan 18, 2013

    Hello there, simply become aware of your weblog through Google, and found that it is truly informative. I am going to be careful for brussels. I’ll appreciate in the event you continue this in future. Many other folks will likely be benefited out of your writing. Cheers!|

  11. Greetings! Very helpful advice within this article!

    It’s the little changes which will make the greatest changes. Many thanks for sharing!

  12. If some one wants to be updated with hottest technologies then he
    must be visit this web page and be up to date all the
    time.

Trackbacks/Pingbacks

  1. DotNetShoutout
  2. DotNetBurner - C#
  3. PimpThisBlog.com

Leave a Reply