Class EmailValidator
- java.lang.Object
-
- org.openstreetmap.josm.data.validation.routines.AbstractValidator
-
- org.openstreetmap.josm.data.validation.routines.EmailValidator
-
public class EmailValidator extends AbstractValidator
Perform email validations.
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.
.- Since:
- Validator 1.4
- Version:
- $Revision: 1741724 $
-
-
Field Summary
Fields Modifier and Type Field Description private booleanallowLocalprivate booleanallowTldprivate static java.util.regex.PatternEMAIL_PATTERNprivate static java.lang.StringEMAIL_REGEXprivate static EmailValidatorEMAIL_VALIDATORSingleton instance of this class, which doesn't consider local addresses as valid.private static EmailValidatorEMAIL_VALIDATOR_WITH_LOCALSingleton instance of this class, which does consider local addresses valid.private static EmailValidatorEMAIL_VALIDATOR_WITH_TLDSingleton instance of this class, which doesn't consider local addresses as valid.private static java.util.regex.PatternIP_DOMAIN_PATTERNprivate static java.lang.StringIP_DOMAIN_REGEXprivate static intMAX_USERNAME_LENprivate static java.lang.StringQUOTED_USERprivate static java.lang.StringSPECIAL_CHARSprivate static java.util.regex.PatternUSER_PATTERNprivate static java.lang.StringUSER_REGEXprivate static java.lang.StringVALID_CHARSprivate static java.lang.StringWORD
-
Constructor Summary
Constructors Modifier Constructor Description protectedEmailValidator(boolean allowLocal, boolean allowTld)Protected constructor for subclasses to use.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static EmailValidatorgetInstance()Returns the Singleton instance of this validator.static EmailValidatorgetInstance(boolean allowLocal)Returns the Singleton instance of this validator, with local validation as required.static EmailValidatorgetInstance(boolean allowLocal, boolean allowTld)Returns the Singleton instance of this validator, with local validation as required.java.lang.StringgetValidatorName()Returns the name of this validatorbooleanisValid(java.lang.String email)Checks if a field has a valid e-mail address.protected booleanisValidDomain(java.lang.String domain)Returns true if the domain component of an email address is valid.protected booleanisValidUser(java.lang.String user)Returns true if the user component of an email address is valid.-
Methods inherited from class org.openstreetmap.josm.data.validation.routines.AbstractValidator
getErrorMessage, setErrorMessage
-
-
-
-
Field Detail
-
SPECIAL_CHARS
private static final java.lang.String SPECIAL_CHARS
- See Also:
- Constant Field Values
-
VALID_CHARS
private static final java.lang.String VALID_CHARS
- See Also:
- Constant Field Values
-
QUOTED_USER
private static final java.lang.String QUOTED_USER
- See Also:
- Constant Field Values
-
WORD
private static final java.lang.String WORD
- See Also:
- Constant Field Values
-
EMAIL_REGEX
private static final java.lang.String EMAIL_REGEX
- See Also:
- Constant Field Values
-
IP_DOMAIN_REGEX
private static final java.lang.String IP_DOMAIN_REGEX
- See Also:
- Constant Field Values
-
USER_REGEX
private static final java.lang.String USER_REGEX
- See Also:
- Constant Field Values
-
EMAIL_PATTERN
private static final java.util.regex.Pattern EMAIL_PATTERN
-
IP_DOMAIN_PATTERN
private static final java.util.regex.Pattern IP_DOMAIN_PATTERN
-
USER_PATTERN
private static final java.util.regex.Pattern USER_PATTERN
-
MAX_USERNAME_LEN
private static final int MAX_USERNAME_LEN
- See Also:
- Constant Field Values
-
allowLocal
private final boolean allowLocal
-
allowTld
private final boolean allowTld
-
EMAIL_VALIDATOR
private static final EmailValidator EMAIL_VALIDATOR
Singleton instance of this class, which doesn't consider local addresses as valid.
-
EMAIL_VALIDATOR_WITH_TLD
private static final EmailValidator EMAIL_VALIDATOR_WITH_TLD
Singleton instance of this class, which doesn't consider local addresses as valid.
-
EMAIL_VALIDATOR_WITH_LOCAL
private static final EmailValidator EMAIL_VALIDATOR_WITH_LOCAL
Singleton instance of this class, which does consider local addresses valid.
-
-
Constructor Detail
-
EmailValidator
protected EmailValidator(boolean allowLocal, boolean allowTld)
Protected constructor for subclasses to use.- Parameters:
allowLocal- Should local addresses be considered valid?allowTld- Should TLDs be allowed?
-
-
Method Detail
-
getInstance
public static EmailValidator getInstance()
Returns the Singleton instance of this validator.- Returns:
- singleton instance of this validator.
-
getInstance
public static EmailValidator getInstance(boolean allowLocal, boolean allowTld)
Returns the Singleton instance of this validator, with local validation as required.- Parameters:
allowLocal- Should local addresses be considered valid?allowTld- Should TLDs be allowed?- Returns:
- singleton instance of this validator
-
getInstance
public static EmailValidator getInstance(boolean allowLocal)
Returns the Singleton instance of this validator, with local validation as required.- Parameters:
allowLocal- Should local addresses be considered valid?- Returns:
- singleton instance of this validator
-
isValid
public boolean isValid(java.lang.String email)
Checks if a field has a valid e-mail address.- Specified by:
isValidin classAbstractValidator- Parameters:
email- The value validation is being performed on. Anullvalue is considered invalid.- Returns:
- true if the email address is valid.
-
getValidatorName
public java.lang.String getValidatorName()
Description copied from class:AbstractValidatorReturns the name of this validator- Specified by:
getValidatorNamein classAbstractValidator- Returns:
- the name of this validator
-
isValidDomain
protected boolean isValidDomain(java.lang.String domain)
Returns true if the domain component of an email address is valid.- Parameters:
domain- being validated, may be in IDN format- Returns:
- true if the email address's domain is valid.
-
isValidUser
protected boolean isValidUser(java.lang.String user)
Returns true if the user component of an email address is valid.- Parameters:
user- being validated- Returns:
- true if the user name is valid.
-
-