How should I validate an e-mail address?

后端 未结 30 2219
臣服心动
臣服心动 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:53

    You can use regular expression to do so. Something like the following.

    Pattern pattern = Pattern.compile(".+@.+\\.[a-z]+");
    
    String email = "xyz@xyzdomain.com";
    
    Matcher matcher = pattern.matcher(email);
    
    boolean matchFound = matcher.matches();
    

    Note: Check the regular expression given above, don't use it as it is.

提交回复
热议问题