private bool IsValidEmail(string email)
{
//regular expression pattern for valid email
//addresses, allows for the following domains:
//com,edu,info,gov,int,mil,net,org,biz,name,museum,coop,aero,pro,tv
string pattern = @"^[-a-zA-Z0-9][-.a-zA-Z0-9]*@[-.a-zA-Z0-9]+(\.[-.a-zA-Z0-9]+)*\.(com|edu|pl|interia|poczta|onet|vp|autograf|spoko|opoczta|windowslive.com|o2|wp|tlen|go2|hotmail|gmail|info|gov|int|mil|net|org|biz|name|museum|coop|aero|pro|tv|[a-zA-Z]{2})$";
//Regular expression object
Regex check = new Regex(pattern, RegexOptions.IgnorePatternWhitespace);
//boolean variable to return to calling method
bool valid = false;
//make sure an email address was provided
if (string.IsNullOrEmpty(email))
{
valid = false;
}
else
{
//use IsMatch to validate the address
valid = check.IsMatch(email);
}
//return the value to the calling method
return valid;
}
czyPoprawnyAdres = IsValidEmail(tBAdresNadawcy.Text);
if (czyPoprawnyAdres == true)
{
tBTrescWiadomosci.Enabled = true;
PocztaGmail poczta = new PocztaGmail();
poczta.wyslij(tBTrescWiadomosci.Text + " " + tBAdresNadawcy.Text);
}
else
{
MessageBox.Show("To nie jest poprawny adres email.", "Komunikat");
tBTrescWiadomosci.Enabled = false;
}
Co mam dopisać w pattern, aby taki email [email protected], był zaliczony jako poprawny adres?