Class DomainValidator
- All Implemented Interfaces:
Serializable
Domain name validation routines.
This validator provides methods for validating Internet domain names and top-level domains.
Domain names are evaluated according to the standards RFC1034, section 3, and RFC1123, section 2.1. No accommodation is provided for the specialized needs of other applications; if the domain name has been URL-encoded, for example, validation will fail even though the equivalent plaintext version of the same name would have passed.
Validation is also provided for top-level domains (TLDs) as defined and maintained by the Internet Assigned Numbers Authority (IANA):
isValidInfrastructureTld(String)- validates infrastructure TLDs (.arpa, etc.)isValidGenericTld(String)- validates generic TLDs (.com, .org, etc.)isValidCountryCodeTld(String)- validates country code TLDs (.us, .uk, .cn, etc.)
(NOTE: This class does not provide IP address lookup for domain names or
methods to ensure that a given domain name matches a specific IP; see
InetAddress for that functionality.)
- Since:
- Validator 1.4
- Version:
- $Revision: 1713225 $
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static enumenum used byupdateTLDOverride(ArrayType, String[])to determine which override array to update.private static class -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final booleanprivate static final String[]private static String[]private static String[]private static final Stringprivate static final Stringprivate static final DomainValidatorSingleton instance of this validator, which doesn't consider local addresses as valid.private static final DomainValidatorSingleton instance of this validator, which does consider local addresses valid.private final RegexValidatorRegexValidator for matching domains.private static final String[]private static final String[]private static String[]private static String[]private final RegexValidatorRegexValidator for matching a local hostnameprivate static final String[]private static booleanprivate static final String[]private static final longprivate static final String -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static booleanarrayContains(String[] sortedArray, String key) Check if a sorted array contains the specified keyprivate StringchompLeadingDot(String str) (package private) static voidstatic DomainValidatorReturns the singleton instance of this validator.static DomainValidatorgetInstance(boolean allowLocal) Returns the singleton instance of this validator, with local validation as required.private static booleanisOnlyASCII(String input) booleanReturns true if the specifiedStringparses as a valid domain name with a recognized top-level domain.booleanisValidCountryCodeTld(String ccTld) Returns true if the specifiedStringmatches any IANA-defined country code top-level domain.(package private) final booleanisValidDomainSyntax(String domain) booleanisValidGenericTld(String gTld) Returns true if the specifiedStringmatches any IANA-defined generic top-level domain.booleanReturns true if the specifiedStringmatches any IANA-defined infrastructure top-level domain.booleanisValidLocalTld(String lTld) Returns true if the specifiedStringmatches any widely used "local" domains (localhost or localdomain).booleanisValidTld(String tld) Returns true if the specifiedStringmatches any IANA-defined top-level domain.(package private) static StringunicodeToASCII(String input) Converts potentially Unicode input to punycode.static voidupdateTLDOverride(DomainValidator.ArrayType table, String[] tlds) Update one of the TLD override arrays.
-
Field Details
-
EMPTY_STRING_ARRAY
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
DOMAIN_LABEL_REGEX
- See Also:
-
TOP_LABEL_REGEX
- See Also:
-
DOMAIN_NAME_REGEX
- See Also:
-
allowLocal
private final boolean allowLocal -
DOMAIN_VALIDATOR
Singleton instance of this validator, which doesn't consider local addresses as valid. -
DOMAIN_VALIDATOR_WITH_LOCAL
Singleton instance of this validator, which does consider local addresses valid. -
domainRegex
RegexValidator for matching domains. -
hostnameRegex
RegexValidator for matching a local hostname -
INFRASTRUCTURE_TLDS
-
GENERIC_TLDS
-
COUNTRY_CODE_TLDS
-
LOCAL_TLDS
-
inUse
private static boolean inUse -
COUNTRY_CODE_TLDS_PLUS
-
GENERIC_TLDS_PLUS
-
COUNTRY_CODE_TLDS_MINUS
-
GENERIC_TLDS_MINUS
-
-
Constructor Details
-
DomainValidator
private DomainValidator(boolean allowLocal) Private constructor.
-
-
Method Details
-
getInstance
Returns the singleton instance of this validator. It will not consider local addresses as valid.- Returns:
- the singleton instance of this validator
-
getInstance
Returns the singleton instance of this validator, with local validation as required.- Parameters:
allowLocal- Should local addresses be considered valid?- Returns:
- the singleton instance of this validator
-
isValid
Returns true if the specifiedStringparses as a valid domain name with a recognized top-level domain. The parsing is case-insensitive.- Parameters:
domain- the parameter to check for domain name syntax- Returns:
- true if the parameter is a valid domain name
-
isValidDomainSyntax
-
isValidTld
Returns true if the specifiedStringmatches any IANA-defined top-level domain. Leading dots are ignored if present. The search is case-insensitive.- Parameters:
tld- the parameter to check for TLD status, not null- Returns:
- true if the parameter is a TLD
-
isValidInfrastructureTld
Returns true if the specifiedStringmatches any IANA-defined infrastructure top-level domain. Leading dots are ignored if present. The search is case-insensitive.- Parameters:
iTld- the parameter to check for infrastructure TLD status, not null- Returns:
- true if the parameter is an infrastructure TLD
-
isValidGenericTld
Returns true if the specifiedStringmatches any IANA-defined generic top-level domain. Leading dots are ignored if present. The search is case-insensitive.- Parameters:
gTld- the parameter to check for generic TLD status, not null- Returns:
- true if the parameter is a generic TLD
-
isValidCountryCodeTld
Returns true if the specifiedStringmatches any IANA-defined country code top-level domain. Leading dots are ignored if present. The search is case-insensitive.- Parameters:
ccTld- the parameter to check for country code TLD status, not null- Returns:
- true if the parameter is a country code TLD
-
isValidLocalTld
Returns true if the specifiedStringmatches any widely used "local" domains (localhost or localdomain). Leading dots are ignored if present. The search is case-insensitive.- Parameters:
lTld- the parameter to check for local TLD status, not null- Returns:
- true if the parameter is an local TLD
-
chompLeadingDot
-
clearTLDOverrides
static void clearTLDOverrides() -
updateTLDOverride
Update one of the TLD override arrays. This must only be done at program startup, before any instances are accessed using getInstance.For example:
DomainValidator.updateTLDOverride(ArrayType.GENERIC_PLUS, new String[]{"apache"})To clear an override array, provide an empty array.
- Parameters:
table- the table to update, seeinvalid reference
DomainValidator#ArrayTypetlds- the array of TLDs, must not be null- Throws:
IllegalStateException- if the method is called after getInstance- Since:
- 1.5.0
-
unicodeToASCII
-
isOnlyASCII
-
arrayContains
-