How do I check if email is valid on Android?

Asked 1 years ago, Updated 1 years ago, 113 views

What are some good techniques for email validation on Android? http://commons.apache.org/proper/commons-validator/apidocs/org/apache/commons/validator/routines/EmailValidator.html I don't think this will work, but is there any other library or regular expression?

android email-validation

2022-09-21 17:35

1 Answers

You can use Patterns from Android API 8 or higher.

public final static boolean isValidEmail(CharSequence target) {
  if (TextUtils.isEmpty(target)) {
    return false;
  } } else {
    return android.util.Patterns.EMAIL_ADDRESS.matcher(target).matches();
  }
}

You can use it like this. Or

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

You can use it like this, too.


2022-09-21 17:35

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.