This sample code snippet helps to validate an email address using regular expressions. Returns true is the address provided is true, otherwise returns false
public bool IsValidEmail(string email)
{
string pat = @"^[-a-zA-Z0-9][-.a-zA-Z0-9]*@[-.a-zA-Z0-9]+(\.[-.a-zA-Z0-9]+)*\.(comeduinfogovintmilnetorgbiznamemuseumcoopaeroprotv[a-zA-Z]{2})$";
Regex check = new Regex(pat,RegexOptions.IgnorePatternWhitespace);
bool valid = false;
if (string.IsNullOrEmpty(email))
{
valid = false;
}
else
{
valid = check.IsMatch(email);
}
return valid;
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment