/**
  * 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)
 {
     if (!is_string($value)) {
         $this->_error(self::INVALID);
         return false;
     }
     $this->_setValue($value);
     if ($this->_encoding !== null) {
         $length = iconv_strlen($value, $this->_encoding);
     } else {
         $length = iconv_strlen($value, 'UTF-8');
     }
     $counter = array_count_values(App_Util_String::strToArray($value));
     foreach (static::$doubleCountChars as $char) {
         if (isset($counter[$char])) {
             $length += $counter[$char];
         }
     }
     if ($length < $this->_min) {
         $this->_error(self::TOO_SHORT);
     }
     if (null !== $this->_max && $this->_max < $length) {
         $this->_error(self::TOO_LONG);
     }
     if (count($this->_messages)) {
         return false;
     } else {
         return true;
     }
 }
Exemplo n.º 2
0
 /**
  * Defined by Zend_Validate_Interface
  *
  * Returns true if and only if $value is a valid postalcode
  *
  * @param string $value
  * @param Default_Model_Organization_Address
  * @return boolean
  */
 public function isValid($value, $context = null)
 {
     if (!is_string($value)) {
         $this->_error(self::INVALID);
         return false;
     }
     $result = array_diff(App_Util_String::strToArray($value), static::$alphabet);
     if (!empty($result)) {
         $this->_error(self::INVALID_CHAR, current($result));
         return false;
     }
     return true;
 }