Monday, April 18, 2011

Email address validation function or method using C#

Use following function to validate your email address in C#.....

public static bool IsEmail(string EmailAddress)
{
    string strRegex = @"^([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})(\]?)$";
    Regex re = new Regex(strRegex);
    if (re.IsMatch(EmailAddress))
        return (true);
    else
        return (false);
}