public function validate($fieldName, $value) { if ($this->isEmpty($value)) { return true; } else { if (!preg_match('/^[-+]?\\d*\\.\\d+$/', $value)) { $this->composeRuleError($fieldName); } else { if (parent::validate($fieldName, $value)) { // additional params if (!empty($this->params)) { $value = floatval($value); foreach ($this->params as $subRuleFlag => $threshold) { $threshold = $this->getSubRuleThreshold($subRuleFlag); switch ($subRuleFlag) { case '.=': if (!preg_match("/^[-+]?\\d*\\.\\d{{$threshold}}\$/", $value)) { $this->composeRuleError($fieldName, $subRuleFlag, $threshold); } break; case '.>': $threshold++; case '.>=': if (!preg_match("/^[-+]?\\d*\\.\\d{" . $threshold . ",}\$/", $value)) { $this->composeRuleError($fieldName, $subRuleFlag, $threshold); } break; } } } } } } return !$this->hasError(); }
public function validate($value) { parent::validate($value); if (!is_integer($value)) { throw new ErrorException("Value has to be integer!"); } }
protected function validate($value) : bool { if (!parent::validate($value)) { return false; } $intval = (int) $value; return $intval == $value; }
public function validate($fieldName, $value) { if ($this->isEmpty($value)) { return true; } else { if (!preg_match('/^[-]?\\d+$/', $value)) { $this->composeRuleError($fieldName); } else { parent::validate($fieldName, $value); } } return !$this->hasError(); }