Some forms requires both start and end dates. The start date must be earlier than the end one. And vice versa, the end date must be later the the start one.
The next sections introduce the solutions for different usages. One is for comparing date, and one for comparing time.
Comparing dates
In order to compare dates, you can use the dynamic optionsmin and max provided by the date validator:
Because the start and end date depend on each other, whenever one of them is changed, we need to revalidate the other if it is not valid:
The start and end date fields in example use the Bootstrap Datepicker plugin, but you can apply the same techniques in the case they do (or don't) use other date picker plugin
The date validator requires the existence of all year, month and day parts. So it can't be used in this case.
To solve our problem, we can use a combination of regexp and callback validators. The first validator is used to check if the input matches with a pattern of time (HH:mm, for example), and the second one for comparing the time.
In the callback method, we respectively compare the start and end time. If start time is earlier than the end one, we need to set the end time as valid by calling the updateStatus() method:
The example uses the verbose: false option and place the callback validator at the end of list of validators. It ensures that the time in the callback method already passes other validators, therefore it matches with the time pattern provided by the regexp validator