public function isValid($value) { parent::isValid($value); if (($length = $this->getOption('max_length', false)) && mb_strlen($value) > $length) { $this->setError($this->getMessage('max_length', array('value' => $value))); } if (($length = $this->getOption('min_length', false)) && mb_strlen($value) < $length) { $this->setError($this->getMessage('min_length', array('value' => $value))); } return $this->getErrors() ? false : true; }
/** * * @param array|string $value * @return type */ public function isValid($value) { parent::isValid($value); if (is_array($value)) { $year = null; if (isset($value['year'])) { $year = $value['year']; if ($year < 0 || $year > date('Y') || !is_numeric($year) || floor($year) != $year) { $this->setError($this->getMessage('incorrect_date')); } } $month = null; if (isset($value['month'])) { $month = $value['month']; if ($month < 1 || $month > 12) { $this->setError($this->getMessage('incorrect_date')); } } $day = null; if (isset($value['day'])) { $day = $value['day']; if ($day < 1) { $this->setError($this->getMessage('incorrect_date')); } } if ($day && $month) { // Febrary if ($month == '2') { if (!$year) { $leap = true; } else { $leap = date("L", strtotime("{$year}-01-01")); } if ($leap && $day > 29) { $this->setError($this->getMessage('incorrect_date')); } if (!$leap && $day > 28) { $this->setError($this->getMessage('incorrect_date')); } } else { if (in_array($month, array('1', '3', '5', '7', '8', '10', '12'))) { if ($day > 31) { $this->setError($this->getMessage('incorrect_date')); } } else { if ($day > 30) { $this->setError($this->getMessage('incorrect_date')); } } } } } else { $time = strtotime($value); if (!$time) { $this->setError($this->getMessage('incorrect_date')); } else { return $this->isValid(array("year" => date("Y", $time), "month" => date("m", $time), "day" => date("d", $time))); } } return $this->getErrors() ? false : true; }
public function isEmpty($value) { if (is_array($value)) { if (empty($value['year']) && empty($value['month']) && empty($value['day'])) { return true; } } else { return parent::isEmpty($value); } }