date format validation YYYY-MM-DD MM-DD-YYYY DD/MM/YYYY
date validation
The key to date validation is the format string. To create a format string, use the following date and/or time elements combined with some delimiter characters. The date/time elements are:- YYYY: year, 4 digits
- YY: year, 2 digits
- M: month, 1 or 2 digits (MM for 2 mandatory digits)
- D: days, 1 or 2 digits (DD for 2 mandatory digits)
- h: hour, 1 or 2 digits (hh for 2 mandatory digits)
- m: minute, 1 or 2 digits (mm for 2 mandatory digits)
- s: seconds, 1 or 2 digits (ss for 2 mandatory digits)
The input is validated syntactically first (number of digits must be correct), then comes the validation against the following rules (if the element exists):
- 1 <= month <= 12
- 1 <= days <= 31
- days must be less or equal than 28, 29, 30 or 31 depending on (leap) year and month
- 0 <= hours <= 23
- 0 <= minutes <= 59
- 0 <= seconds <= 59
Furthermore, you can specify whether the date is required or not: not required date fields may be empty.
- Live examples:
'validation' => Array( Array( 'type' => 'date', 'required' => 0 | 1, 'format' => formatstring ) )
