public class EmailValidator extends AbstractValidator
Perform email validations.
This class is a Singleton; you can retrieve the instance via the getInstance() method.
Based on a script by Sandeep V. Tamhankar http://javascript.internet.com
This implementation is not guaranteed to catch all possible errors in an email address. For example, an address like nobody@noplace.somedog will pass validator, even though there is no TLD "somedog"
.Modifier and Type | Field and Description |
---|---|
private boolean |
allowLocal |
private static Pattern |
EMAIL_PATTERN |
private static String |
EMAIL_REGEX |
private static EmailValidator |
EMAIL_VALIDATOR
Singleton instance of this class, which
doesn't consider local addresses as valid.
|
private static EmailValidator |
EMAIL_VALIDATOR_WITH_LOCAL
Singleton instance of this class, which does
consider local addresses valid.
|
private static Pattern |
IP_DOMAIN_PATTERN |
private static String |
IP_DOMAIN_REGEX |
private static String |
LEGAL_ASCII_REGEX |
private static Pattern |
MATCH_ASCII_PATTERN |
private static String |
QUOTED_USER |
private static String |
SPECIAL_CHARS |
private static Pattern |
USER_PATTERN |
private static String |
USER_REGEX |
private static String |
VALID_CHARS |
private static String |
WORD |
Modifier | Constructor and Description |
---|---|
protected |
EmailValidator(boolean allowLocal)
Protected constructor for subclasses to use.
|
Modifier and Type | Method and Description |
---|---|
static EmailValidator |
getInstance()
Returns the Singleton instance of this validator.
|
static EmailValidator |
getInstance(boolean allowLocal)
Returns the Singleton instance of this validator,
with local validation as required.
|
boolean |
isValid(String email)
Checks if a field has a valid e-mail address.
|
protected boolean |
isValidDomain(String domain)
Returns true if the domain component of an email address is valid.
|
protected boolean |
isValidUser(String user)
Returns true if the user component of an email address is valid.
|
getErrorMessage, getFix, setErrorMessage, setFix
private static final String SPECIAL_CHARS
private static final String VALID_CHARS
private static final String QUOTED_USER
private static final String WORD
private static final String LEGAL_ASCII_REGEX
private static final String EMAIL_REGEX
private static final String IP_DOMAIN_REGEX
private static final String USER_REGEX
private static final Pattern MATCH_ASCII_PATTERN
private static final Pattern EMAIL_PATTERN
private static final Pattern IP_DOMAIN_PATTERN
private static final Pattern USER_PATTERN
private final boolean allowLocal
private static final EmailValidator EMAIL_VALIDATOR
private static final EmailValidator EMAIL_VALIDATOR_WITH_LOCAL
protected EmailValidator(boolean allowLocal)
allowLocal
- Should local addresses be considered valid?public static EmailValidator getInstance()
public static EmailValidator getInstance(boolean allowLocal)
allowLocal
- Should local addresses be considered valid?public boolean isValid(String email)
Checks if a field has a valid e-mail address.
isValid
in class AbstractValidator
email
- The value validation is being performed on. A null
value is considered invalid.protected boolean isValidDomain(String domain)
domain
- being validated.protected boolean isValidUser(String user)
user
- being validated