* @package tao */ class tao_helpers_form_validators_Regex extends tao_helpers_form_Validator { public function setOptions(array $options) { parent::setOptions($options); if (!$this->hasOption('format')) { throw new common_Exception("Please set the format options (define your regular expression)!"); } if ($this->hasOption('message')) { $this->setMessage($this->getOption('message')); } } /** * Short description of method evaluate * * @access public * @author Joel Bout, * @param values * @return boolean */ public function evaluate($values) { $returnValue = false; if (is_string($values) || is_numeric($values)) { $returnValue = (preg_match($this->getOption('format'), $values) === 1); } return $returnValue; } protected function getDefaultMessage() { return __('The format of this field is not valid.'); } }