Date Enforce Rules
The date enforce rules provide functionality to validate and manipulate date values. This documentation covers the isDate
, isAfter
, isBefore
, and isISO8601
rules, along with their options and configurations.
These rule exposes the validator.js
date rule, and accepts the same options.
isDate Rule
The isDate
rule checks whether a given value is a valid date. It accepts various options to customize the validation behavior.
enforce(value).isDate(options);
Options
The isDate
rule accepts an optional options
object to customize the validation behavior. The available options are as follows:
Option | Default Value | Description |
---|---|---|
format | 'YYYY/MM/DD' | A string specifying the expected date format. The default format is 'YYYY/MM/DD' . |
strictMode | false | A boolean value indicating whether strict mode should be enabled. In strict mode, only strings matching the format are valid. |
delimiters | ['/', '-'] | An array of allowed date delimiters. By default, both '/' and '-' are considered valid delimiters. |
Valid Date Formats
The format
option accepts various valid date formats, including:
'YYYY/MM/DD'
'YY/MM/DD'
'YYYY-MM-DD'
'YY-MM-DD'
'MM/DD/YYYY'
'MM/DD/YY'
'MM-DD-YYYY'
'MM-DD-YY'
'DD/MM/YYYY'
'DD/MM/YY'
'DD-MM-YYYY'
'DD-MM-YY'