How should I validate an e-mail address?

后端 未结 30 2170
臣服心动
臣服心动 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条回答
  •  闹比i
    闹比i (楼主)
    2020-11-22 08:53

    Try this simple method which can not accept the email address beginning with digits:

    boolean checkEmailCorrect(String Email) {
        if(signupEmail.length() == 0) {
            return false;
        }
    
        String pttn = "^\\D.+@.+\\.[a-z]+";
        Pattern p = Pattern.compile(pttn);
        Matcher m = p.matcher(Email);
    
        if(m.matches()) {
            return true;
        }
    
        return false;
    }
    

提交回复
热议问题