mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-09-05 11:02:40 +00:00
Relax the 'my' and 'ym' date validation formats.
All other formats that include 'y' allow 2006 or 06. These formats are now conformant with the other formats available. Closes #2436
This commit is contained in:
parent
15c390586f
commit
e15d1652ed
2 changed files with 18 additions and 13 deletions
|
@ -290,8 +290,8 @@ class Validation {
|
|||
* dMy 27 December 2006 or 27 Dec 2006
|
||||
* Mdy December 27, 2006 or Dec 27, 2006 comma is optional
|
||||
* My December 2006 or Dec 2006
|
||||
* my 12/2006 separators can be a space, period, dash, forward slash
|
||||
* ym 2006/12 separators can be a space, period, dash, forward slash
|
||||
* my 12/2006 or 12/06 separators can be a space, period, dash, forward slash
|
||||
* ym 2006/12 or 06/12 separators can be a space, period, dash, forward slash
|
||||
* y 2006 just the year without any separators
|
||||
* @param string $regex If a custom regular expression is used this is the only validation that will occur.
|
||||
* @return boolean Success
|
||||
|
@ -304,6 +304,7 @@ class Validation {
|
|||
$separator = '([- /.])';
|
||||
$fourDigitYear = '(([1][9][0-9][0-9])|([2][0-9][0-9][0-9]))';
|
||||
$twoDigitYear = '([0-9]{2})';
|
||||
$year = '(?:' . $fourDigitYear . '|' . $twoDigitYear . ')';
|
||||
|
||||
$regex['dmy'] = '%^(?:(?:31(\\/|-|\\.|\\x20)(?:0?[13578]|1[02]))\\1|(?:(?:29|30)' .
|
||||
$separator . '(?:0?[1,3-9]|1[0-2])\\2))(?:(?:1[6-9]|[2-9]\\d)?\\d{2})$|^(?:29' .
|
||||
|
@ -325,8 +326,8 @@ class Validation {
|
|||
$regex['My'] = '%^(Jan(uary)?|Feb(ruary)?|Ma(r(ch)?|y)|Apr(il)?|Ju((ly?)|(ne?))|Aug(ust)?|Oct(ober)?|(Sep(?=\\b|t)t?|Nov|Dec)(ember)?)' .
|
||||
$separator . '((1[6-9]|[2-9]\\d)\\d{2})$%';
|
||||
|
||||
$regex['my'] = '%^(' . $month . $separator . $fourDigitYear . ')$%';
|
||||
$regex['ym'] = '%^(' . $fourDigitYear . $separator . $month . ')$%';
|
||||
$regex['my'] = '%^(' . $month . $separator . $year . ')$%';
|
||||
$regex['ym'] = '%^(' . $year . $separator . $month . ')$%';
|
||||
$regex['y'] = '%^(' . $fourDigitYear . ')$%';
|
||||
|
||||
$format = (is_array($format)) ? array_values($format) : array($format);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue