C# code to validate email address - Stack Overflow
using System.Text.RegularExpressions;
public static class EmailValidator {
static Regex ValidEmailRegex = new Regex(
@"^(?!\.)(""([^""\r\\]|\\[""\r\\])*""|"
+ @"([-a-z0-9!#$%&'*+/=?^_`{|}~]|(?<!\.)\.)*)(?<!\.)"
+ @"@[a-z0-9][\w\.-]*[a-z0-9]\.[a-z][a-z\.]*[a-z]$"
, RegexOptions.IgnoreCase);
}
public static bool IsValid(string emailAddress) {
return ValidEmailRegex.IsMatch(emailAddress);
}
}
No comments:
Post a Comment