/** * (non-PHPdoc) * @see lib/form/validator/phValidator::validate() */ public function validate($value, phValidatable $errors) { if (is_array($value)) { throw new phValidatorException('I cannot validate elements that return multiple values'); } $valid = strlen($value) > 0; if (!$valid) { $errors->addError($this->getError(self::REQUIRED)); } return $valid; }
/** * (non-PHPdoc) * @see lib/form/validator/phValidator::validate() */ public function validate($value, phValidatable $errors) { if (is_array($value)) { throw new phValidatorException('I cannot validate elements that return multiple values'); } if ($value == '') { return true; } $valid = $this->isValidEmail($value); if (!$valid) { $errors->addError($this->getError(self::INVALID)); } return $valid; }
/** * (non-PHPdoc) * @see lib/form/validator/phValidator::validate() */ public function validate($value, phValidatable $errors) { $compareValue = $this->_compareWith instanceof phData ? $this->_compareWith->getValue() : $this->_compareWith; $valid = false; switch ($this->_operator) { case self::EQUAL: $valid = $value == $compareValue; break; case self::NOT_EQUAL: $valid = $value != $compareValue; break; case self::GREATER_THAN: $valid = $value > $compareValue; break; case self::GREATER_EQUAL: $valid = $value >= $compareValue; break; case self::LESS_THAN: $valid = $value < $compareValue; break; case self::LESS_EQUAL: $valid = $value <= $compareValue; break; } if (!$valid) { $errors->addError($this->getError(self::INVALID)); } return $valid; }
public function validate($value, phValidatable $errors) { if (is_array($value)) { throw new phValidatorException('I cannot validate elements that return multiple values'); } $length = strlen($value); $valid = true; if ($this->_min !== null && $length < $this->_min) { $valid = false; } else { if ($this->_max !== null && $length > $this->_max) { $valid = false; } } if (!$valid) { $errors->addError($this->getError(self::INVALID)); } return $valid; }
public function validate($value, phValidatable $errors) { if ($this->_required && $value === null) { $errors->addError($this->getError(self::REQUIRED)); return; } if ($value === null) { return; // go no further, no file passed } $data = new phFileFormDataItem('parse'); try { $data->bind($value); } catch (phFileDataException $e) { $errors->addError($this->getError(self::FILE_ERROR, array('%error%' => 'invalid file data'))); return; // no point in going further, bad data } if ($this->_required && !file_exists($data->getTempFileName())) { $errors->addError($this->getError(self::REQUIRED)); return; } if ($data->hasError()) { $errors->addError($this->getError(self::FILE_ERROR, array('%error%' => $data->getFileErrorString()))); return; // no point in going further, bad data } if (sizeof($this->_mimeTypes) > 0 && !in_array($data->getMimeType(), $this->_mimeTypes)) { $validTypes = ''; foreach ($this->_mimeTypes as $m) { $validTypes .= $m . ', '; } $errors->addError($this->getError(self::INVALID_MIME_TYPE, array('%types%' => substr($validTypes, 0, -2)))); return; } }
public function validate($value, phValidatable $item) { $item->addError(new phValidatorError($this->_message, self::FAIL_CODE, $this)); return false; }