Home >Java >javaTutorial >How Can I Efficiently Validate Email Addresses in Java?

How Can I Efficiently Validate Email Addresses in Java?

Susan Sarandon
Susan SarandonOriginal
2024-12-07 03:28:09521browse

How Can I Efficiently Validate Email Addresses in Java?

Best Java Email Address Validation Method

Validate email addresses efficiently in Java. Consider using the official Java mail package for ease of use:

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

This code snippet leverages Java's built-in email validation capabilities to determine the validity of an email address.

The above is the detailed content of How Can I Efficiently Validate Email Addresses in Java?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn