csharp Validate Email

using System.Text.RegularExpressions;

//http://msdn.microsoft.com/en-us/library/01escwtf.aspx
public class RegexUtilities
{
   public static bool IsValidEmail(string strIn)
   {
       // Return true if strIn is in valid e-mail format.
       return Regex.IsMatch(strIn, @"^(?("")("".+?""@)|(([0-9a-zA-Z]((\.(?!\.))|[-!#\$%&'\*\+/=\?\^`\{\}\|~\w])*)(?<=[0-9a-zA-Z])@))" + @"(?(\[)(\[(\d{1,3}\.){3}\d{1,3}\])|(([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,6}))$"); 
   }
}

//example call:
RegexUtilities.IsValidEmail("abc@example.com");
Validates an email address using Regular Expression.

Updated: Saturday 9th October 2010, 10:59pm

There are 0 comments

Leave a comment of your own

Comments are currently closed.