Created
April 8, 2017 16:03
-
-
Save aalonzolu/0569e9bc531ecc29daa929c6945515e8 to your computer and use it in GitHub Desktop.
Java check valid email
This file contains hidden or 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
/** | |
* Created by lexo on 4/8/17. | |
*/ | |
public class validacion { | |
public boolean isCorreo(String correo, boolean validarDominio){ | |
boolean contiene = correo.toLowerCase().contains("@"); | |
if(contiene){ | |
// si tiene arroba | |
String[] parts = correo.split("@"); | |
// validar que solo haya una arroba (dos partes spliteados) | |
if(parts.length ==2){ | |
// validar si hay texto adelante y detras | |
if(parts[0].length() >0 && parts[1].length() >0 ){ | |
if(validarDominio){ | |
// verificar si tiene el . en la seguda parte (luego de la arroba) | |
boolean contiene2 = parts[1].toLowerCase().contains("."); | |
if(contiene2){ | |
// correo valido | |
return true; | |
} | |
else { | |
// correo invalido | |
return false; | |
} | |
} | |
else{ | |
return true; | |
} | |
} | |
else { | |
// arroba mal posicionada | |
return false; | |
} | |
} | |
else{ | |
// si tiene mas de dos arrobas | |
return false; | |
} | |
} | |
// si no contiene arroba | |
return false; | |
} | |
public boolean isGmail(String correo){ | |
boolean contiene = correo.toLowerCase().contains("@gmail.com"); | |
if(contiene) { | |
return true; | |
} | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment