Sunday, 20 November 2011

simple way to validate email field- Android

simple way to validate email field, client side on Android.



private boolean isValidEmail(String email) {


    Pattern p = Pattern.compile(".+@.+\\.[a-z]+");
    Matcher m = p.matcher(email);
    boolean matchFound = m.matches();
    StringTokenizer st = new StringTokenizer(email, ".");
    String lastToken = null;
    while (st.hasMoreTokens()) {
        lastToken = st.nextToken();
    }
    if (matchFound && lastToken.length() >= 2
        && email.length() - 1 != lastToken.length()) {
        return true;
    } else {
        return false;
    }
    }