Last active
January 20, 2017 14:14
Star
You must be signed in to star a gist
Función de validación de la forma de las cuentas de correo con expresiones regulares en Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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