Skip to content

Instantly share code, notes, and snippets.

@jasmin-mistry
Created January 28, 2014 13:43
Show Gist options
  • Save jasmin-mistry/8667878 to your computer and use it in GitHub Desktop.
Save jasmin-mistry/8667878 to your computer and use it in GitHub Desktop.
using System.Text.RegularExpressions;
public static class EMailValidator
{
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 EmailIsValid(string emailAddress)
{
bool isValid = ValidEmailRegex.IsMatch(emailAddress);
return isValid;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment