E-mail validation using regular expression

public bool IsValidEmail(string email)
{
string pat = @"^[-a-zA-Z0-9][-.a-zA-Z0-9]*@[-.a-zA-Z0-9]+(\.[-.a-zA-Z0-9]+)*\.
(com|edu|info|gov|int|mil|net|org|biz|name|museum|coop|aero|pro|tv|[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;
}


Comments

Author: priya08 Nov 2008 Member Level: Bronze   Points : 0



  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: