Created
October 14, 2018 08:10
-
-
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 <[email protected]>` and `[email protected]`
This file contains hidden or 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