Class WDateValidator

java.lang.Object

public class WDateValidator
extends WValidator
A validator for date input.

This validator accepts input in the given date format, and optionally checks if the date is within a given range.

The format string used are the ones accepted by java.text.SimpleDateFormat

i18n

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

  • Wt.WDateValidator.DateTooEarly: The date must be after {1}
  • Wt.WDateValidator.DateTooLate: The date must be before {1}
  • Wt.WDateValidator.WrongDateRange: The date must be between {1} and {2}
  • Wt.WDateValidator.WrongFormat: Must be a date in the format '{1}'
  • Constructor Details

    • WDateValidator

      public WDateValidator​(WObject parent)
      Creates a date validator.

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

    • WDateValidator

      public WDateValidator()
      Creates a date validator.

      Calls this((WObject)null)

    • WDateValidator

      public WDateValidator​(WDate bottom, WDate top, WObject parent)
      Creates a date validator.

      The validator will accept dates in the indicated range using the current locale's format.

    • WDateValidator

      public WDateValidator​(WDate bottom, WDate top)
      Creates a date validator.

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

    • WDateValidator

      public WDateValidator​(java.lang.String format, WObject parent)
      Creates a date validator.

      The validator will accept dates in the date format format.

    • WDateValidator

      public WDateValidator​(java.lang.String format)
      Creates a date validator.

      Calls this(format, (WObject)null)

    • WDateValidator

      public WDateValidator​(java.lang.String format, WDate bottom, WDate top, WObject parent)
      Creates a date validator.

      The validator will accept only dates within the indicated range bottom to top, in the date format format.

    • WDateValidator

      public WDateValidator​(java.lang.String format, WDate bottom, WDate top)
      Creates a date validator.

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

  • Method Details

    • setBottom

      public void setBottom​(WDate bottom)
      Sets the bottom of the valid date range.

      The default is a null date constructed using WDate().

    • getBottom

      public WDate getBottom()
      Returns the bottom date of the valid range.
    • setTop

      public void setTop​(WDate top)
      Sets the top of the valid date range.

      The default is a null date constructed using WDate().

    • getTop

      public WDate getTop()
      Returns the top date of the valid range.
    • setFormat

      public void setFormat​(java.lang.String format)
      Sets the date format used to parse date strings.
    • getFormat

      public java.lang.String getFormat()
      Returns the format string used to parse date strings.

      Overrides:
      getFormat in class WValidator
      See Also:
      setFormat(String format)
    • setFormats

      public void setFormats​(java.util.List<java.lang.String> formats)
      Sets the date formats used to parse date strings.
    • getFormats

      public java.util.List<java.lang.String> getFormats()
      Returns the date formats used to parse date strings.
    • 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 a date in the given format, and within the valid range.

      Overrides:
      validate in class WValidator
    • setInvalidNotADateText

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

      The default message is "The date must be of the format {1}", with as first argument the format string.

    • getInvalidNotADateText

      public WString getInvalidNotADateText()
      Returns the message displayed when the input is not a date.

      See Also:
      setInvalidNotADateText(CharSequence text)
    • setInvalidTooEarlyText

      public void setInvalidTooEarlyText​(java.lang.CharSequence text)
      Sets the message to display when the date is earlier than bottom.

      The default message is "The date must be between {1} and {2}" or "The date must be after {1}".

    • getInvalidTooEarlyText

      public WString getInvalidTooEarlyText()
      Returns the message displayed when date is too early.

      See Also:
      setInvalidTooEarlyText(CharSequence text)
    • setInvalidTooLateText

      public void setInvalidTooLateText​(java.lang.CharSequence text)
      Sets the message to display when the date is later than top.

      Depending on whether getBottom() and getTop() are defined, the default message is "The date must be between {1} and {2}" or "The date must be before {2}".

    • getInvalidTooLateText

      public WString getInvalidTooLateText()
      Returns the message displayed when the date is too late.

      See Also:
      setInvalidTooLateText(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()