Search code examples
androidandroid-edittextemail-validation

How to check edittext's text is email address or not?


how to check the text of edittext is email address or not without using javascript and regular expression? Here I used inputtype="textEmailAddress" this is working but no error message is display.


Solution

  • /**
     * method is used for checking valid email id format.
     * 
     * @param email
     * @return boolean true for valid false for invalid
     */
    public static boolean isEmailValid(String email) {
        String expression = "^[\\w\\.-]+@([\\w\\-]+\\.)+[A-Z]{2,4}$";
        Pattern pattern = Pattern.compile(expression, Pattern.CASE_INSENSITIVE);
        Matcher matcher = pattern.matcher(email);
        return matcher.matches();
    }
    

    Pass your edit text string in this function .

    for right email verification you need server side authentication


    Note there is now a built-in method in Android, see answers below.