Jojooa

Validar un Email en c# .NET

Para validar en c# debemos comparar la cadena de caracteres que forman el email con la siguiente expresión regular:

/// <returns> True: valido False: dirección incorrecta </returns>
public bool EsMailValido(string to)
{
try
{
//return System.Text.RegularExpressions.Regex.IsMatch(to, @»^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$»);
return System.Text.RegularExpressions.Regex.IsMatch(to, @»^(([^<>()[\]\\.,;:\s@\»»]+»
+ @»(\.[^<>()[\]\\.,;:\s@\»»]+)*)|(\»».+\»»))@»
+ @»((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}»
+ @»\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+»
+ @»[a-zA-Z]{2,}))$»);

}
catch (Exception e)
{
throw new ApplicationException(«validar email», e);
}
}

Exit mobile version