setPattern($pattern); } /** * Returns the pattern option * * @return string */ public function getPattern() { return $this->_pattern; } /** * Sets the pattern option * * @param string $pattern * @return Zend_Validate_Regex Provides a fluent interface */ public function setPattern($pattern) { $this->_pattern = (string) $pattern; return $this; } /** * Defined by Zend_Validate_Interface * * Returns true if and only if $value matches against the pattern option * * @param string $value * @throws Zend_Validate_Exception if there is a fatal error in pattern matching * @return boolean */ public function isValid($value) { $this->_messages = array(); $valueString = (string) $value; $status = @preg_match($this->_pattern, $valueString); if (false === $status) { /** * @see Zend_Validate_Exception */ require_once 'Zend/Validate/Exception.php'; throw new Zend_Validate_Exception("Internal error matching pattern '$this->_pattern' against value '$valueString'"); } if (!$status) { $this->_messages[] = "'$valueString' does not match against pattern '$this->_pattern'"; return false; } return true; } /** * Defined by Zend_Validate_Interface * * Returns array of validation failure messages * * @return array */ public function getMessages() { return $this->_messages; } }