Class WLengthValidator

java.lang.Object
eu.webtoolkit.jwt.WObject
eu.webtoolkit.jwt.WValidator
eu.webtoolkit.jwt.WLengthValidator

public class WLengthValidator
extends WValidator
A validator that checks the string length of user input.

This validator checks whether user input is within the specified range of accepted string lengths.

If you only want to limit the length on a line edit, you may also use WLineEdit#setMaxLength().

i18n

The strings used in this class can be translated by overriding the default values for the following localization keys:

  • Wt.WLengthValidator.TooShort: The input must be at least {1} characters
  • Wt.WLengthValidator.BadRange: The input must have a length between {1} and {2} characters
  • Wt.WLengthValidator.TooLong: The input must be no more than {1} characters
  • Constructor Details

    • WLengthValidator

      public WLengthValidator​(WObject parent)
      Creates a length validator that accepts input of any length.
    • WLengthValidator

      public WLengthValidator()
      Creates a length validator that accepts input of any length.

      Calls this((WObject)null)

    • WLengthValidator

      public WLengthValidator​(int minLength, int maxLength, WObject parent)
      Creates a length validator that accepts input within a length range.
    • WLengthValidator

      public WLengthValidator​(int minLength, int maxLength)
      Creates a length validator that accepts input within a length range.

      Calls this(minLength, maxLength, (WObject)null)

  • Method Details

    • setMinimumLength

      public void setMinimumLength​(int minLength)
      Sets the minimum length.

      The default value is 0.

    • getMinimumLength

      public int getMinimumLength()
      Returns the minimum length.

      See Also:
      setMinimumLength(int minLength)
    • setMaximumLength

      public void setMaximumLength​(int maxLength)
      Sets the maximum length.

      The default value is the maximum integer value.

    • getMaximumLength

      public int getMaximumLength()
      Returns the maximum length.

      See Also:
      setMaximumLength(int maxLength)
    • validate

      public WValidator.Result validate​(java.lang.String input)
      Validates the given input.

      The input is considered valid only when it is blank for a non-mandatory field, or has a length within the valid range.

      Overrides:
      validate in class WValidator
    • setInvalidTooShortText

      public void setInvalidTooShortText​(java.lang.CharSequence text)
      Sets the message to display when the input is too short.

      Depending on whether getMaximumLength() is a real bound, the default message is "The input must have a length between {1} and {2} characters" or " "The input must be at least {1} characters".

    • getInvalidTooShortText

      public WString getInvalidTooShortText()
      Returns the message displayed when the input is too short.

      See Also:
      setInvalidTooShortText(CharSequence text)
    • setInvalidTooLongText

      public void setInvalidTooLongText​(java.lang.CharSequence text)
      Sets the message to display when the input is too long.

      Depending on whether getMinimumLength() is different from zero, the default message is "The input must have a length between {1} and {2} characters" or " "The input must be no more than {2} characters".

    • getInvalidTooLongText

      public WString getInvalidTooLongText()
      Returns the message displayed when the input is too long.

      See Also:
      setInvalidTooLongText(CharSequence text)
    • getJavaScriptValidate

      public java.lang.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.

      Note: The signature and contract changed changed in JWt 3.1.9.

      Overrides:
      getJavaScriptValidate in class WValidator
      See Also:
      WValidator.getInputFilter()