Regular Expression for EMail address validation
30-06-2005 15:45
к комментариям - к полной версии
- понравилось!
if (Regex.IsMatch(email.Text, @"^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$") == false)
{
return "error";
}
Вот и готовый пример:
public Boolean IsValidEmailAddress(String address)
{
if (address == null || address.Length == 0)
return false;
Regex rx = new Regex(@"[^A-Za-z0-9@\-_.]", RegexOptions.Compiled);
MatchCollection matches = rx.Matches(address);
if (matches.Count > 0)
return false;
// Must have an ‘@’ character
int i = address.IndexOf('@');
// Must be at least three chars after the @
if (i <= 0 || i >= address.Length - 3)
return false;
// Must only be one ‘@’ character
if (address.IndexOf('@', i + 1) >= 0)
return false;
// Find the last . in the address
int j = address.LastIndexOf('.');
// The dot can't be before or immediately after the @ char
if (j >= 0 && j <= i + 1)
return false;
return true;
}
вверх^
к полной версии
понравилось!
в evernote