Class EmailValidator

java.lang.Object
com.dlsc.gemsfx.util.EmailValidator

public final class EmailValidator extends Object
Validates whether a string is a well-formed email address.

The check covers the common subset of RFC 5321 / 5322: local-part@domain, where:

  • The local part may contain letters, digits, and the characters !#$%&'*+/=?^_`{|}~-, with internal dots allowed between non-dot segments (dots are not permitted at the start or end, nor consecutively).
  • The domain consists of dot-separated labels. Each label may contain letters, digits, and hyphens, but must start and end with a letter or digit.
  • The top-level domain must consist of at least two alphabetic characters.
  • The total address length must not exceed 254 characters (RFC 5321 §4.5.3).

This class is intentionally minimal. More complex formats (IP-address literals, quoted local parts, …) are not supported.

Use getInstance() to obtain the shared, stateless singleton.

  • Method Details

    • getInstance

      public static EmailValidator getInstance()
      Returns the shared singleton instance.
      Returns:
      the shared singleton instance
    • isValid

      public boolean isValid(String email)
      Returns true if email is a well-formed address according to the rules described in the class Javadoc.
      Parameters:
      email - the address to check; null always yields false
      Returns:
      true if the address is valid