Skip to content

Instantly share code, notes, and snippets.

@McKabue
Created October 14, 2018 08:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save McKabue/2a4ab0c590d704950497cf54503aeb90 to your computer and use it in GitHub Desktop.
Save McKabue/2a4ab0c590d704950497cf54503aeb90 to your computer and use it in GitHub Desktop.
This handy extention validates email address with and without a display name. e.g: `Kabue Charles <me@mckabue.com>` and `me@mckabue.com`
/// <summary>
/// https://stackoverflow.com/a/1374644
/// </summary>
/// <param name="email"></param>
/// <returns></returns>
public static bool IsValidEmail(this string email)
{
try
{
var addr = new System.Net.Mail.MailAddress(email);
return new System.ComponentModel.DataAnnotations.EmailAddressAttribute().IsValid(addr.Address);
}
catch (Exception)
{
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment