Wt
4.11.3
|
A basic validator for email input. More...
#include <Wt/WEmailValidator.h>
Public Member Functions | |
WEmailValidator () | |
Creates an email validator. | |
Result | validate (const WString &input) const override |
Validates the given input. More... | |
void | setInvalidNotAnEmailAddressText (const WString &text) |
Sets the message to display when the input is not a valid email address. More... | |
WString | invalidNotAnEmailAddressText () const |
Returns the message displayed when the input is not a valid email address. More... | |
void | setInvalidNotMatchingText (const WString &text) |
Sets the message to display when the input does not match the required pattern. More... | |
WString | invalidNotMatchingText () const |
Returns the message displayed when the input does not match the required pattern. More... | |
void | setMultiple (bool multiple) |
Sets whether multiple comma-separated email addresses are allowed. More... | |
bool | multiple () const |
Returns whether multiple comma-separated email addresses are allowed. More... | |
void | setPattern (const WString &pattern) |
Sets the pattern for the input validation. More... | |
WString | pattern () const |
Returns the pattern used for the input validation. More... | |
std::string | javaScriptValidate () const override |
Creates a Javascript object that validates the input. More... | |
![]() | |
WValidator (bool mandatory=false) | |
Creates a new validator. More... | |
virtual | ~WValidator () |
Destructor. More... | |
void | setMandatory (bool how) |
Sets if input is mandatory. More... | |
bool | isMandatory () const |
Returns if input is mandatory. | |
void | setInvalidBlankText (const WString &text) |
Sets the message to display when a mandatory field is left blank. More... | |
WString | invalidBlankText () const |
Returns the message displayed when a mandatory field is left blank. More... | |
virtual WString | format () const |
Returns the validator format. More... | |
virtual std::string | inputFilter () const |
Returns a regular expression that filters input. More... | |
Additional Inherited Members | |
![]() | |
typedef ValidationState | State |
Typedef for enum Wt::ValidationState. | |
A basic validator for email input.
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.
WString Wt::WEmailValidator::invalidNotAnEmailAddressText | ( | ) | const |
Returns the message displayed when the input is not a valid email address.
WString Wt::WEmailValidator::invalidNotMatchingText | ( | ) | const |
Returns the message displayed when the input does not match the required pattern.
|
overridevirtual |
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:
message
that indicates the problem if not valid.Returns an empty string if the validator does not provide a client-side validation implementationq.
Reimplemented from Wt::WValidator.
bool Wt::WEmailValidator::multiple | ( | ) | const |
Returns whether multiple comma-separated email addresses are allowed.
WString Wt::WEmailValidator::pattern | ( | ) | const |
Returns the pattern used for the input validation.
The pattern is in ECMAScript style regex.
void Wt::WEmailValidator::setInvalidNotAnEmailAddressText | ( | const WString & | text | ) |
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 multiple() is false
, or tr("Wt.WEmailValidator.Invalid.Multiple") if multiple() is true
.
void Wt::WEmailValidator::setInvalidNotMatchingText | ( | const WString & | text | ) |
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 the pattern. This string is retrieved using tr("Wt.WEmailValidator.NotMaching") if multiple() is false
, or tr("Wt.WEmailValidator.NotMaching.Multiple") if multiple() is true
.
void Wt::WEmailValidator::setMultiple | ( | bool | multiple | ) |
Sets whether multiple comma-separated email addresses are allowed.
void Wt::WEmailValidator::setPattern | ( | const WString & | pattern | ) |
Sets the pattern for the input validation.
The pattern is in ECMAScript style regex.
|
overridevirtual |
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 pattern() if non-empty.
Reimplemented from Wt::WValidator.