setMin($min); $this->setMax($max); } /** * Returns the min option * * @return integer */ public function getMin() { return $this->_min; } /** * Sets the min option * * @param integer $min * @return Zend_Validate_StringLength Provides a fluent interface */ public function setMin($min) { $this->_min = max(0, (integer) $min); return $this; } /** * Returns the max option * * @return integer|null */ public function getMax() { return $this->_max; } /** * Sets the max option * * @param integer|null $max * @return Zend_Validate_StringLength Provides a fluent interface */ public function setMax($max) { if (null === $max) { $this->_max = null; } else { $this->_max = (integer) $max; } return $this; } /** * Defined by Zend_Validate_Interface * * Returns true if and only if the string length of $value is at least the min option and * no greater than the max option (when the max option is not null). * * @param string $value * @return boolean */ public function isValid($value) { $this->_messages = array(); $valueString = (string) $value; $length = strlen($valueString); if ($length < $this->_min) { $this->_messages[] = "'$valueString' is less than $this->_min characters long"; } if (null !== $this->_max && $this->_max < $length) { $this->_messages[] = "'$valueString' is greater than $this->_max characters long"; } if (count($this->_messages)) { return false; } else { return true; } } /** * Defined by Zend_Validate_Interface * * Returns array of validation failure messages * * @return array */ public function getMessages() { return $this->_messages; } }