Geeks With Blogs

News My Blog has been MOVED to
Michael Freidgeim's OLD Blog My Blog has been MOVED to

I needed to validate customer email addresses. Many articles suggested to use different regEx , but they are not the same and not easy to identify, which is the best. So i decided to use MailAddress, which throw exception if MS implemented validation failed.
It world be good if the class would provide Validate or TryParse method to avoid costly exception.

    /// <summary>
    ////    Validating E-mail address    

/// </summary>

public static class MailHelper
        //TODO: use Reflector or find some code to validate address as strict as ParseValue , for now just catch Exception
    public static string ValidateEmailFormat(string email)
            MailAddress from = new MailAddress(email);
        catch (Exception exc)
            string sMsg = exc.Message;
            return sMsg;
        return "";


Also I found a few articles about validating E-mail Against the Mail server. I wish to implement this in a future. -Short and clear explanation of approach, JSCRIPT ASP Validating E-mail Against the Mail server VB.Net C#,reference to  Peter  Bromberg’s C# SMTP Mail without SMTP Service or CDO

Posted on Wednesday, June 8, 2011 7:13 AM .Net Framework | Back to top

Comments on this post: Validating an email address

# re: Validating an email address
Requesting Gravatar...
good idea if you validate one email. because with a lot of emails, a trycatch is just awful for performance
Left by lg on Jun 08, 2011 7:37 AM

Your comment:
 (will show your gravatar)

Copyright © Michael Freidgeim | Powered by: