diff --git a/cake/libs/validation.php b/cake/libs/validation.php index a727029b8..a923d1844 100644 --- a/cake/libs/validation.php +++ b/cake/libs/validation.php @@ -322,14 +322,35 @@ class Validation extends Object { $this->_extract($check); } if($this->regex === null){ - $this->errors[] = __('You must define a regular expression for Validation::custom()'); + $this->errors[] = __('You must define a regular expression for Validation::custom()', true); return false; } return $this->_check(); } - function date($check) { + function date($check, $format = 'dmy', $regex = null) { + $this->__reset(); + $this->check = $check; + $this->regex = $regex; + $search = array(); + if(is_array($format)){ + foreach($format as $key => $value){ + $search[$value] = $value; + } + } else { + $search[$format] = $format; + } + $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})$%'; + + foreach ($search as $key){ + $this->regex = $regex[$key]; + + if($this->_check() === true){ + return true; + } + } + return false; } function decimal($check, $type, $regex= null) {