Skip to content

Instantly share code, notes, and snippets.

@aalonzolu
Created April 8, 2017 16:03
Show Gist options
  • Save aalonzolu/0569e9bc531ecc29daa929c6945515e8 to your computer and use it in GitHub Desktop.
Save aalonzolu/0569e9bc531ecc29daa929c6945515e8 to your computer and use it in GitHub Desktop.
Java check valid email
/**
* 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