From 3ca4762d32d8e610b6541b47e8b293307293167c Mon Sep 17 00:00:00 2001 From: phpnut Date: Thu, 9 Nov 2006 16:26:54 +0000 Subject: [PATCH] Adding Validation::date() implementation for: mm/dd/yyyy mm/dd/yy m/d/yy m/d/yyyy yyyy/mm/dd yy/mm/dd y/m/d/ /yyyy/m/d/ git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@3853 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/validation.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cake/libs/validation.php b/cake/libs/validation.php index a923d1844..71280960e 100644 --- a/cake/libs/validation.php +++ b/cake/libs/validation.php @@ -328,7 +328,7 @@ class Validation extends Object { return $this->_check(); } - function date($check, $format = 'dmy', $regex = null) { + function date($check, $format = 'ymd', $regex = null) { $this->__reset(); $this->check = $check; $this->regex = $regex; @@ -341,7 +341,9 @@ class Validation extends Object { } else { $search[$format] = $format; } + $regex['mdy'] = '%^(?:(?:(?:0?[13578]|1[02])(\\/|-|\\.|\\x20)31)\\1|(?:(?:0?[13-9]|1[0-2])(\\/|-|\\.|\\x20)(?:29|30)\\2))(?:(?:1[6-9]|[2-9]\\d)?\\d{2})$|^(?:0?2(\\/|-|\\.|\\x20)29\\3(?:(?:(?:1[6-9]|[2-9]\\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:(?:0?[1-9])|(?:1[0-2]))(\\/|-|\\.|\\x20)(?:0?[1-9]|1\\d|2[0-8])\\4(?:(?:1[6-9]|[2-9]\\d)?\\d{2})$%'; $regex['dmy'] = '%^(?:(?:31(\\/|-|\\.|\\x20)(?:0?[13578]|1[02]))\\1|(?:(?:29|30)(\\/|-|\\.|\\x20)(?:0?[1,3-9]|1[0-2])\\2))(?:(?:1[6-9]|[2-9]\\d)?\\d{2})$|^(?:29(\\/|-|\\.|\\x20)0?2\\3(?:(?:(?:1[6-9]|[2-9]\\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:0?[1-9]|1\\d|2[0-8])(\\/|-|\\.|\\x20)(?:(?:0?[1-9])|(?:1[0-2]))\\4(?:(?:1[6-9]|[2-9]\\d)?\\d{2})$%'; + $regex['ymd'] = '%^(?:(?:(?:(?:(?:1[6-9]|[2-9]\\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00)))(\\/|-|\\.|\\x20)(?:0?2\\1(?:29)))|(?:(?:(?:1[6-9]|[2-9]\\d)?\\d{2})(\\/|-|\\.|\\x20)(?:(?:(?:0?[13578]|1[02])\\2(?:31))|(?:(?:0?[1,3-9]|1[0-2])\\2(29|30))|(?:(?:0?[1-9])|(?:1[0-2]))\\2(?:0?[1-9]|1\\d|2[0-8]))))$%'; foreach ($search as $key){ $this->regex = $regex[$key];