Monday, June 3, 2013

Validar el formato de un E-mail en Android

Se puede hacer con el siguiente método:

public static boolean isEmailValid(String email) {
    boolean isValid = false;

    String expression = "^[\\w\\.-]+@([\\w\\-]+\\.)+[A-Z]{2,4}$";
    CharSequence inputStr = email;

    Pattern pattern = Pattern.compile(expression, Pattern.CASE_INSENSITIVE);
    Matcher matcher = pattern.matcher(inputStr);
    if (matcher.matches()) {
        isValid = true;
    }
    return isValid;
}

Gracias a la expresión regular indicada arriba, el método devolverá true si el formato es válido y false en caso contrario.

fuente

Bookmark and Share

No comments:

Related Posts Plugin for WordPress, Blogger...