public class EmailPropertyType extends PropertyType<String>
^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$to validate that the string is a valid email address.
Constructor Example | Comments | ||
---|---|---|---|
Property<String> A_PROPERTY = |
No domain name constraints, default value is null. | ||
Property<String> A_PROPERTY = |
Domain name must be "domain.com", default value is null. | ||
Property<String> A_PROPERTY = |
Domain name must be "domain.com", default value is "manager@domain.com". | ||
Property<String> A_PROPERTY = |
No domain name constraints, default value is "manager@domain.com". | ||
Property<String> A_PROPERTY = |
No domain name constraints, default value is null. | ||
Type of value(s) | Examples | Result | Comments |
Valid | test@test.com | A string validated as an email | Validate successfully. |
Invalid | cow | null |
Validate will throw an exception. The resulting value is null . |
Invalid | «empty string» | null |
|
Invalid | «empty string after trim» | null |
|
Invalid | null |
defaultValue OR null |
Validate will throw an exception. Return default value if set, otherwise null . |
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_DNS_TIMEOUT_INITIAL_MS
The default timeout value in milliseconds, when checking the MX record for the domain part in the email address.
|
static int |
DEFAULT_DNS_TIMEOUT_RETRIES
The default retries value, when checking the MX record for the domain part in the email address.
|
static String |
EMAIL_PATTERN
The regular expression pattern that is used check if a string is a valid email.
|
static String |
GOOGLE_PUBLIC_DNS_1
Googles public DNS - "dns://8.8.8.8".
|
static String |
GOOGLE_PUBLIC_DNS_2
Googles public DNS - "dns://8.8.4.4".
|
static String |
TYPE
The type name string constant of EmailPropertyType.
|
Constructor and Description |
---|
EmailPropertyType()
Creates a email property type, where the is no domain restrictions.
|
EmailPropertyType(String domainMustContain)
Creates a email property type, with no default value.
|
EmailPropertyType(String defaultValue,
String domainMustContain)
Creates a email property type.
|
Modifier and Type | Method and Description |
---|---|
String |
getDomainMustContain()
The substring that the 'domain' part of the email must contain.
|
protected String |
getDomainPart(String value)
Gets the domain/hostname part of an email address.
Everything after "@". |
static String |
getOverrideDNSUrl()
Returns the override DNS URL.
|
List<String> |
getRestrictions()
Gets a detailed description of the PropertyType with any constraints that might influence the validation.
|
static int |
getStaticDnsTimeoutInitialMs()
The timeout value in milliseconds, when checking the MX record for the domain part in the email address.
|
static int |
getStaticDnsTimeoutRetries()
The retries value, when checking the MX record for the domain part in the email address.
|
boolean |
isValidatingDomain()
Determines if domain validation shall be performed.
|
void |
setDomainMustContain(String domainMustContain)
Sets the substring that the 'domain' part of the email must contain.
|
static void |
setOverrideDNSUrl(String dnsUrl)
Sets the override DNS URL.
|
static void |
setStaticDnsTimeoutInitialMs(int dnsTimeoutInitialMs)
The timeout value in milliseconds, when checking the MX record for the domain part in the email address.
|
static void |
setStaticDnsTimeoutRetries(int dnsTimeoutRetries)
The retries value, when checking the MX record for the domain part in the email address.
|
void |
setValidatingDomain(boolean validateDomain)
Set if domain validation shall be performed.
Default set to true . |
protected void |
validateDomain(String propertyName,
String value,
String domain) |
String |
validateValue(String propertyName,
String value)
Converts the string representation of to a typed value.
|
equals, getDefaultValue, getDefaultValueAsString, getDefaultValueDescription, getDescription, getDescription, getInitializationPriority, getIo, getLogger, getTypeName, hasDefaultValue, isDefaultValueValid, postGetValueProcessing, setDefaultValue, setInitializationPriority, setIo, setTypedValue, setTypeName, toString, toType, validate, validateConstraints, validateNullType
public static final String TYPE
public static int DEFAULT_DNS_TIMEOUT_INITIAL_MS
public static int DEFAULT_DNS_TIMEOUT_RETRIES
public static String GOOGLE_PUBLIC_DNS_1
setOverrideDNSUrl(String)
,
getOverrideDNSUrl()
public static String GOOGLE_PUBLIC_DNS_2
setOverrideDNSUrl(String)
,
getOverrideDNSUrl()
public static final String EMAIL_PATTERN
^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$
public EmailPropertyType()
nullAllowed
is false.public EmailPropertyType(String domainMustContain)
domainMustContain
- a substring that the 'domain' part of the email must contain. Not case sensitive. If null
than not used.public EmailPropertyType(String defaultValue, String domainMustContain)
defaultValue
- default value returned if property value is undefined.domainMustContain
- the substring that the 'domain' part of the email must contain. Not case sensitive. If null
than not used.public String getDomainMustContain()
null
than not used.public void setDomainMustContain(String domainMustContain)
domainMustContain
- the domain constraints.public List<String> getRestrictions()
PropertyType
getRestrictions
in class PropertyType<String>
public String validateValue(String propertyName, String value) throws PropertyException
PropertyType
validateValue
in class PropertyType<String>
propertyName
- the name of the property used for logging purposes. To uniquely identify the Property with validation issues.value
- the string representation of the propertyPropertyException
- if the conversion failed.protected String getDomainPart(String value) throws NullPointerException
value
- the email addressNullPointerException
- if value is null
.protected void validateDomain(String propertyName, String value, String domain) throws PropertyException
PropertyException
public void setValidatingDomain(boolean validateDomain)
true
.validateDomain
- set to true
if domain validation shall be performed, otherwise false
.public boolean isValidatingDomain()
true
if domain validation shall be performed, otherwise false
.public static int getStaticDnsTimeoutInitialMs()
setValidatingDomain(boolean)
public static int getStaticDnsTimeoutRetries()
public static void setStaticDnsTimeoutInitialMs(int dnsTimeoutInitialMs)
dnsTimeoutInitialMs
- the static dnsTimeoutRetries to set, must greather than 0 otherwise default value of 2000 is used.DEFAULT_DNS_TIMEOUT_INITIAL_MS
public static void setStaticDnsTimeoutRetries(int dnsTimeoutRetries)
dnsTimeoutRetries
- the static dnsTimeoutRetries to set, must greather than 0 otherwise default value of 1 is used.DEFAULT_DNS_TIMEOUT_RETRIES
public static String getOverrideDNSUrl()
OVERRIDE_DNS_URL
public static void setOverrideDNSUrl(String dnsUrl)
null
using the standard internal URL. dnsUrl
- the override DNS URL.