Skip to content

Date Validations

Compare
Choose a tag to compare
@logaretm logaretm released this 27 Aug 16:31
· 4556 commits to main since this release

Date validations are now available as those rules:

  • date_format:{format} validates that the field under validation must have a valid date according to the provided format.
  • after:{target} validates that the field under validation must have a valid date and is after the target input date value.
  • before:{target} validates that the field under validation must have a valid date and is before the target input date value.
  • date_between:{min,max} validates that the field under validation must have a valid date that is between the min date and the maximum date.

These validators require momentjs in order to work, you have to call validator.installDateTimeValidators(moment) and pass momentjs reference to install the validators, they are installed automatically if you have it referenced globally.

All date rules above require date_format rule to be present, since validations occur from left to right, date_format must exist before any of the other date rules. This is because it is recommended by momentjs to parse all dates with specific formats to avoid errors as much as possible. the parsing mode is always strict to further reduce parsing errors, and ultimately validation false-positives.

Strict Mode

The validators now operate by default in strict mode, which when validating non-attached fields returns false. you can turn it off using $validator.setStrictMode(false) which will turn it off for the validator instance or Validator.setStrictMode(false) to turn it off for all newly created validators.

Many thanks for:

  • @gig3m for identifying and helping fix a critical issue, also for implementing strict mode.
  • @hootlex for fixing a dead link in the docs.