How should I validate an e-mail address?

后端 未结 30 1666
臣服心动
臣服心动 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 08:58

    Next pattern is used in K-9 mail:

    public static final Pattern EMAIL_ADDRESS_PATTERN = Pattern.compile(
              "[a-zA-Z0-9\\+\\.\\_\\%\\-\\+]{1,256}" +
              "\\@" +
              "[a-zA-Z0-9][a-zA-Z0-9\\-]{0,64}" +
              "(" +
              "\\." +
              "[a-zA-Z0-9][a-zA-Z0-9\\-]{0,25}" +
              ")+"
          );
    

    You can use function

    private boolean checkEmail(String email) {
            return EMAIL_ADDRESS_PATTERN.matcher(email).matches();
    }
    

提交回复
热议问题