Wt  4.10.4
Public Member Functions | List of all members
Wt::WEmailValidator Class Reference

A basic validator for email input. More...

#include <Wt/WEmailValidator.h>

Inheritance diagram for Wt::WEmailValidator:
[legend]

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...
 
- Public Member Functions inherited from Wt::WValidator
 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

- Public Types inherited from Wt::WValidator
typedef ValidationState State
 Typedef for enum Wt::ValidationState.
 

Detailed Description

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.

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.

Member Function Documentation

◆ invalidNotAnEmailAddressText()

WString Wt::WEmailValidator::invalidNotAnEmailAddressText ( ) const

Returns the message displayed when the input is not a valid email address.

See also
setInvalidNotAnEmailAddressText(const WString& text)

◆ invalidNotMatchingText()

WString Wt::WEmailValidator::invalidNotMatchingText ( ) const

Returns the message displayed when the input does not match the required pattern.

See also
setInvalidNotMatchingText(const WString& text)

◆ javaScriptValidate()

std::string Wt::WEmailValidator::javaScriptValidate ( ) const
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:

  • 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.

See also
inputFilter()

Reimplemented from Wt::WValidator.

◆ multiple()

bool Wt::WEmailValidator::multiple ( ) const

Returns whether multiple comma-separated email addresses are allowed.

See also
setMultiple(bool multiple)

◆ pattern()

WString Wt::WEmailValidator::pattern ( ) const

Returns the pattern used for the input validation.

The pattern is in ECMAScript style regex.

See also
setPattern(WString pattern)

◆ setInvalidNotAnEmailAddressText()

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.

See also
invalidNotAnEmailAddressText()

◆ setInvalidNotMatchingText()

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.

See also
invalidNotMatchingText()

◆ setMultiple()

void Wt::WEmailValidator::setMultiple ( bool  multiple)

Sets whether multiple comma-separated email addresses are allowed.

See also
multiple()

◆ setPattern()

void Wt::WEmailValidator::setPattern ( const WString pattern)

Sets the pattern for the input validation.

The pattern is in ECMAScript style regex.

See also
pattern()

◆ validate()

WValidator::Result Wt::WEmailValidator::validate ( const WString input) const
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.