Skip to content

Instantly share code, notes, and snippets.

@donpandix
Last active January 20, 2017 14:14
Show Gist options
  • Save donpandix/68dc90a2cde27106c4b960074dce3c17 to your computer and use it in GitHub Desktop.
Save donpandix/68dc90a2cde27106c4b960074dce3c17 to your computer and use it in GitHub Desktop.
Función de validación de la forma de las cuentas de correo con expresiones regulares en Java
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class FN {
/**
* Valida la forma de una dirección de correo
* @param email cadena de texto con el email a validar
* @return
*/
public static Boolean validaEmail (String email) {
Pattern pattern = Pattern.compile("^([0-9a-zA-Z]+[-._+&])*[0-9a-zA-Z]+@([-0-9a-zA-Z]+[.])+[a-zA-Z]{2,6}$");
Matcher matcher = pattern.matcher(email);
return matcher.matches();
}
// Elemplo de implementación
public static void main (String[] args) {
if ( ! FN.validaEmail("soyEmail@invalido") {
System.out.println("Email malo!!!");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment