0
 private boolean isValidEmail(String email){

    boolean isValid = false;

    String expression = "^(([\\w-]+\\.)+[\\w-]+|([a-zA-Z]{1}|[\\w-]{2,}))@"
            +"((([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\\.([0-1]?"
            +"[0-9]{1,2}|25[0-5]|2[0-4][0-9])\\."
            +"([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\\.([0-1]?"
            +"[0-9]{1,2}|25[0-5]|2[0-4][0-9])){1}|"
            +"([a-zA-Z]+[\\w-]+\\.)+[a-zA-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;
}

I'm using this code to check email address in valid or not. But in case of UTF-8 (Non-english), it is valid. I want to check email format including UTF-8. Please help.

Halo
  • 729
  • 1
  • 8
  • 18
  • 1
    see here link http://stackoverflow.com/questions/7554827/validating-email-address-which-contains-non-english-utf-8-character-in-java and this http://stackoverflow.com/questions/1819142/how-should-i-validate-an-e-mail-address-on-android – rajshree Mar 04 '14 at 10:16

2 Answers2

2

You can use android pattern for e-mails:

boolean isEmailValid(CharSequence email) {
   return android.util.Patterns.EMAIL_ADDRESS.matcher(email).matches();
}
Unii
  • 1,587
  • 15
  • 33
0

try this..hope so it will help you

public static boolean isValidMailID(String toAddress) {
            if(!isBasicallyValidEmailAddress(toAddress) || toAddress.indexOf('.') == -1)
                return false;
            int index1 = toAddress.lastIndexOf('.');
            int index2 = toAddress.lastIndexOf('@');

            if(toAddress.endsWith("."))
                return false ;

            if( index1 < index2 || (index2 + 1) >= index1)
                return false;
            return true;
        }

        private static boolean isBasicallyValidEmailAddress(String email) {
            if (email == null) {
                return false;
            }
            boolean atFound = false;
            for (int i = 0; i < email.length(); i++) {
                char c = email.charAt(i);
                if ((c < 'a' || c > 'z') && (c < 'A' || c > 'Z') && (c < '0' || c > '9') && !isAtextSymbol(c)) {
                    return false;
                }
                if (c == '@') {
                    if (atFound) {
                        return false;
                    }
                    atFound = true;
                }
            }
            return atFound;
        }

        public static boolean isAtextSymbol(char c) {
            for (int i = 0; i < ATEXT_SYMBOLS.length; i++) {
                if (c == ATEXT_SYMBOLS[i]) {
                    return true;
                }
            }
            return false;
        }

where you want to apply call method isValidMailId(pass your mail id)...

Anjali Tripathi
  • 1,477
  • 9
  • 28