Class WEmailValidator
This validator does basic email validation, to check if an email address is formed correctly according to the WHATWG email input specification: https://html.spec.whatwg.org/multipage/input.html#email-state-(type=email)
This validator can also be used for multiple
email addresses.
A regex pattern
can be specified to
check that email addresses comply with this pattern.
Note: This validator only checks that the email address is correctly formed, but does not do any further checks. If you need to be sure that the email address is valid, then we recommend that you either send a confirmation email or use an email address verification service.
-
Nested Class Summary
Nested classes/interfaces inherited from class eu.webtoolkit.jwt.WValidator
WValidator.Result
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionReturns the message displayed when the input is not a valid email address.Returns the message displayed when the input does not match the required pattern.Creates a Javascript object that validates the input.Returns the pattern used for the input validation.boolean
Returns whether multiple comma-separated email addresses are allowed.void
Sets the message to display when the input is not a valid email address.void
Sets the message to display when the input does not match the required pattern.void
setMultiple
(boolean multiple) Sets whether multiple comma-separated email addresses are allowed.void
setPattern
(CharSequence pattern) Sets the pattern for the input validation.Validates the given input.Methods inherited from class eu.webtoolkit.jwt.WValidator
getFormat, getInputFilter, getInvalidBlankText, isMandatory, setInvalidBlankText, setMandatory
-
Constructor Details
-
WEmailValidator
public WEmailValidator()Creates an email validator.
-
-
Method Details
-
validate
Validates the given input.The input is considered valid only when it is blank for a non-mandatory field, or represents a properly formed email address, or a list of email addresses, and matches the
getPattern()
if non-empty.- Overrides:
validate
in classWValidator
-
setInvalidNotAnEmailAddressText
Sets the message to display when the input is not a valid email address.The default message is "Must be a valid email address". This string is retrieved using tr("Wt.WEmailValidator.Invalid") if
isMultiple()
isfalse
, or tr("Wt.WEmailValidator.Invalid.Multiple") ifisMultiple()
istrue
.- See Also:
-
getInvalidNotAnEmailAddressText
Returns the message displayed when the input is not a valid email address. -
setInvalidNotMatchingText
Sets the message to display when the input does not match the required pattern.The default message is "Must be an email address matching the pattern '{1}'", with
{1}
subsituted by thegetPattern()
. This string is retrieved using tr("Wt.WEmailValidator.NotMaching") ifisMultiple()
isfalse
, or tr("Wt.WEmailValidator.NotMaching.Multiple") ifisMultiple()
istrue
.- See Also:
-
getInvalidNotMatchingText
Returns the message displayed when the input does not match the required pattern. -
setMultiple
public void setMultiple(boolean multiple) Sets whether multiple comma-separated email addresses are allowed.- See Also:
-
isMultiple
public boolean isMultiple()Returns whether multiple comma-separated email addresses are allowed.- See Also:
-
setPattern
Sets the pattern for the input validation.The pattern is in ECMAScript style regex.
- See Also:
-
getPattern
Returns the pattern used for the input validation.The pattern is in ECMAScript style regex.
-
getJavaScriptValidate
Description copied from class:WValidator
Creates a Javascript object that validates the input.The JavaScript expression should evaluate to an object which contains a
validate(text)
function, which returns an object that contains the following two fields:- fields: a boolean valid,
- a
message
that indicates the problem if not valid.
Returns an empty string if the validator does not provide a client-side validation implementationq.
- Overrides:
getJavaScriptValidate
in classWValidator
- See Also:
-