Class WEmailValidator

java.lang.Object
eu.webtoolkit.jwt.WValidator
eu.webtoolkit.jwt.WEmailValidator

public class WEmailValidator extends WValidator
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.

  • Constructor Details

    • WEmailValidator

      public WEmailValidator()
      Creates an email validator.
  • Method Details

    • validate

      public WValidator.Result validate(String input)
      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 class WValidator
    • setInvalidNotAnEmailAddressText

      public void setInvalidNotAnEmailAddressText(CharSequence 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 isMultiple() is false, or tr("Wt.WEmailValidator.Invalid.Multiple") if isMultiple() is true.

      See Also:
    • getInvalidNotAnEmailAddressText

      public WString getInvalidNotAnEmailAddressText()
      Returns the message displayed when the input is not a valid email address.

      See Also:
    • setInvalidNotMatchingText

      public void setInvalidNotMatchingText(CharSequence 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 getPattern(). This string is retrieved using tr("Wt.WEmailValidator.NotMaching") if isMultiple() is false, or tr("Wt.WEmailValidator.NotMaching.Multiple") if isMultiple() is true.

      See Also:
    • getInvalidNotMatchingText

      public WString getInvalidNotMatchingText()
      Returns the message displayed when the input does not match the required pattern.

      See Also:
    • 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

      public void setPattern(CharSequence pattern)
      Sets the pattern for the input validation.

      The pattern is in ECMAScript style regex.

      See Also:
    • getPattern

      public WString getPattern()
      Returns the pattern used for the input validation.

      The pattern is in ECMAScript style regex.

    • getJavaScriptValidate

      public String 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 class WValidator
      See Also: