Sponsored Ad

Monday, March 22, 2010

Email Validation in C# | Validate Email Address Format using Regular Expression

While working i found that if we are using any email field, We always need a email validator.

I created a utility using regular expressions to validate the email format.

You just need to pass email is as a input and it will return you that email id is valid or not.

Please go through it and let me know in case of any problem while using it.

use name space using System.Text.RegularExpressions; to compile this code.

 

using System.Text.RegularExpressions;

      /// <summary>
      /// Validate email address format.
      /// </summary>
      public static bool IsValidEmail(string Email)
      {
          return Regex.IsMatch(Email, @"\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*");
      }

2 comments:

  1. Hi I just want to know how to get that regular Expression of Email-id or Phone number.

    ReplyDelete
  2. Regular Expression for Phone number (USA)
    ex. 800-555-555

    ^[2-9]\d{2}-\d{3}-\d{4}$

    ReplyDelete

Sponsored Ad

Website Update

Followers