How should I validate an e-mail address?

后端 未结 30 1640
臣服心动
臣服心动 2020-11-22 08:25

What\'s a good technique for validating an e-mail address (e.g. from a user input field) in Android? org.apache.commons.validator.routines.EmailValidator doesn\'t seem to be

30条回答
  •  既然无缘
    2020-11-22 09:07

    Call This Method where you want to validate email ID.

    public static boolean isValid(String email)
    {
       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()) 
       {
          return true;
       }
       else{
       return false;
       }
    }
    

提交回复
热议问题