Whether you use a regular expression or the .NET Framework example, please remember that both check only the
format of an email address.
They do not ascertain if the email address actually exists in a mailbox server.
C# Example
public static bool isValidEmail(string inputEmail)
{
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(inputEmail))
return (true);
else
return (false);
}
An article on email address format validation using a Regular Expression
How to Find or Validate an Email Address[
^]
.NET Framework Example
This example uses the .NET MailAddress Class to validate the format of an email address.
bool IsValidEmail(string email)
{
try {
var mail = new System.Net.Mail.MailAddress(email);
return true;
}
catch {
return false;
}
}