How should I validate an e-mail address?

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

    Use simple one line code for email Validation

    public static boolean isValidEmail(CharSequence target) {
        return !TextUtils.isEmpty(target) && android.util.Patterns.EMAIL_ADDRESS.matcher(target).matches();
    }
    

    use like...

    if (!isValidEmail(yourEdittext.getText().toString()) {
        Toast.makeText(context, "your email is not valid", 2000).show();
    }
    

提交回复
热议问题