Created
May 11, 2017 13:55
-
-
Save ted80/a7281bf96a658a54f16ddf8e27f42c1b to your computer and use it in GitHub Desktop.
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
using System.Text.RegularExpressions; | |
public static class MailString | |
{ | |
static Regex ValidEmailRegex = CreateValidEmailRegex(); | |
private static Regex CreateValidEmailRegex () | |
{ | |
string validEmailPattern = @"^(?!\.)(""([^""\r\\]|\\[""\r\\])*""|" + @"([-a-z0-9!#$%&'*+/=?^_`{|}~]|(?<!\.)\.)*)(?<!\.)" + @"@[a-z0-9][\w\.-]*[a-z0-9]\.[a-z][a-z\.]*[a-z]$"; | |
return new Regex( validEmailPattern, RegexOptions.IgnoreCase ); | |
} | |
internal static bool isEmailValid (string emailAddress) | |
{ | |
if (!((!string.IsNullOrEmpty( emailAddress )) && ValidEmailRegex.IsMatch( emailAddress ))) | |
{ | |
return false; | |
} | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment