Adding Validation::date() implementation for dd/mm/yyyy dd/mm/yy d/m/yy d/m/yyyy

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@3851 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
phpnut 2006-11-09 14:19:32 +00:00
parent fa3e71d169
commit 678e1be889

View file

@ -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) {