Class WIntValidator

java.lang.Object

public class WIntValidator
extends WValidator
A validator that validates integer user input.

This validator checks whether user input is an integer number in a pre-defined range.

i18n

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

  • Wt.WIntValidator.NotAnInteger: Must be an integer number
  • Wt.WIntValidator.TooSmall: The number must be larger than {1}
  • Wt.WIntValidator.BadRange: The number must be in the range {1} to {2}
  • Wt.WIntValidator.TooLarge: The number must be smaller than {1}
  • Constructor Details

    • WIntValidator

      public WIntValidator​(WObject parent)
      Creates a new integer validator that accepts any integer.

      The validator will accept numbers using the current locale's format.

    • WIntValidator

      public WIntValidator()
      Creates a new integer validator that accepts any integer.

      Calls this((WObject)null)

    • WIntValidator

      public WIntValidator​(int bottom, int top, WObject parent)
      Creates a new integer validator that accepts integer input within the given range.
    • WIntValidator

      public WIntValidator​(int bottom, int top)
      Creates a new integer validator that accepts integer input within the given range.

      Calls this(bottom, top, (WObject)null)

  • Method Details

    • getBottom

      public int getBottom()
      Returns the bottom of the valid integer range.
    • setBottom

      public void setBottom​(int bottom)
      Sets the bottom of the valid integer range.

      The default value is the minimum integer value.

    • getTop

      public int getTop()
      Returns the top of the valid integer range.
    • setTop

      public void setTop​(int top)
      Sets the top of the valid integer range.

      The default value is the maximum integer value.

    • setRange

      public void setRange​(int bottom, int top)
      Sets the range of valid integers.
    • 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 represents an integer within the valid range.

      Overrides:
      validate in class WValidator
    • setInvalidNotANumberText

      public void setInvalidNotANumberText​(java.lang.CharSequence text)
      Sets the message to display when the input is not a number.

      The default value is "Must be an integer number."

    • getInvalidNotANumberText

      public WString getInvalidNotANumberText()
      Returns the message displayed when the input is not a number.

      See Also:
      setInvalidNotANumberText(CharSequence text)
    • setInvalidTooSmallText

      public void setInvalidTooSmallText​(java.lang.CharSequence text)
      Sets the message to display when the number is too small.

      Depending on whether getBottom() and getTop() are real bounds, the default message is "The number must be between {1} and {2}" or "The number must be larger than {1}".

    • getInvalidTooSmallText

      public WString getInvalidTooSmallText()
      Returns the message displayed when the number is too small.

      See Also:
      setInvalidTooSmallText(CharSequence text)
    • setInvalidTooLargeText

      public void setInvalidTooLargeText​(java.lang.CharSequence text)
      Sets the message to display when the number is too large.

      Depending on whether getBottom() and getTop() are real bounds, the default message is "The number must be between {1} and {2}" or "The number must be smaller than {2}".

    • getInvalidTooLargeText

      public WString getInvalidTooLargeText()
      Returns the message displayed when the number is too large.

      See Also:
      setInvalidTooLargeText(CharSequence text)
    • setIgnoreTrailingSpaces

      public void setIgnoreTrailingSpaces​(boolean b)
      If true the validator will ignore trailing spaces.

      See Also:
      isIgnoreTrailingSpaces()
    • isIgnoreTrailingSpaces

      public boolean isIgnoreTrailingSpaces()
      Indicates whether the validator should ignore the trailing spaces.

      See Also:
      setIgnoreTrailingSpaces(boolean b)
    • 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()
    • getInputFilter

      public java.lang.String getInputFilter()
      Description copied from class: WValidator
      Returns a regular expression that filters input.

      The returned regular expression is used to filter keys presses. The regular expression should accept valid single characters.

      For details on valid regular expressions, see WRegExpValidator. As an example, "[0-9]" would only accept numbers as valid input.

      The default implementation returns an empty string, which does not filter any input.

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