Created
October 14, 2018 07:55
-
-
Save McKabue/d3a3bd8dd67dcef5d8934804ce9e51ff 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`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <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