Currently I am using below code to validate email
public static bool IsValidEmail(string email)
{
var r = new Regex(@"^([0-9a-zA-Z]([-\.\'\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$");
return !string.IsNullOrEmpty(email) && r.IsMatch(email);
}
Now want to validate this "[email protected]" email as valid email id. what change needs to be done in regex?
([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+That's only matching sub-domains that start and end with an alphanumeric, and therefore must have 2 characters. But I still wouldn't try to "fix" the regex, because a regex is never going to be 100% right. Stop trying to use a hammer for everything, use the right tool. If you want to check if an email is valid, try to send a verification code.