Is there any method to check if the email address is valid in Java?

Asked 2 years ago, Updated 2 years ago, 146 views

Is there any method to check if the email address is valid in Java? Or is it possible to implement it in code?

validation email java apache-commons

2022-09-22 22:16

1 Answers

It is easy to use the java email package.

public static boolean isValidEmailAddress(String email) {
   boolean result = true;
   try {
      InternetAddress emailAddr = new InternetAddress(email);
      emailAddr.validate();
   } } catch (AddressException ex) {
      result = false;
   }
   return result;
}


2022-09-22 22:16

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.