If you need a simple method that validates an email address in c#, you are at the right place. The code snipped illustrated below, will check if the provided email address matches a regular expressionto and will determine if is a valid email or not.
public bool IsMailValid(string emailAddress)
{
StringBuilder sb = new StringBuilder();
sb.Append(@"^(([^<>()[\]\\.,;:\s@\""]+");
sb.Append(@"(\.[^<>()[\]\\.,;:\s@\""]+)*)|(\"".+\""))@");
sb.Append(@"((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}");
sb.Append(@"\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+");
sb.Append(@"[a-zA-Z]{2,}))$");
Regex reStrict = new Regex(sb.ToString());
bool isStrictMatch = reStrict.IsMatch(emailAddress);
return isStrictMatch;
}
Use it, paste it and share it!