Example #1
0
 /**
  * Defined by Postman_Zend_Validate_Interface
  *
  * Returns true if and only if $value is a valid integer
  *
  * @param  string|integer $value
  * @return boolean
  */
 public function isValid($value)
 {
     if (!is_string($value) && !is_int($value) && !is_float($value)) {
         $this->_error(self::INVALID);
         return false;
     }
     if (is_int($value)) {
         return true;
     }
     $this->_setValue($value);
     if ($this->_locale === null) {
         $locale = localeconv();
         $valueFiltered = str_replace($locale['decimal_point'], '.', $value);
         $valueFiltered = str_replace($locale['thousands_sep'], '', $valueFiltered);
         if (strval(intval($valueFiltered)) != $valueFiltered) {
             $this->_error(self::NOT_INT);
             return false;
         }
     } else {
         try {
             if (!Postman_Zend_Locale_Format::isInteger($value, array('locale' => $this->_locale))) {
                 $this->_error(self::NOT_INT);
                 return false;
             }
         } catch (Postman_Zend_Locale_Exception $e) {
             $this->_error(self::NOT_INT);
             return false;
         }
     }
     return true;
 }
Example #2
0
 /**
  * Check if the given date fits the given format
  *
  * @param  string $value  Date to check
  * @return boolean False when date does not fit the format
  */
 private function _checkFormat($value)
 {
     try {
         require_once 'Zend/Locale/Format.php';
         $parsed = Postman_Zend_Locale_Format::getDate($value, array('date_format' => $this->_format, 'format_type' => 'iso', 'fix_date' => false));
         if (isset($parsed['year']) and (strpos(strtoupper($this->_format), 'YY') !== false and strpos(strtoupper($this->_format), 'YYYY') === false)) {
             $parsed['year'] = Postman_Zend_Date::getFullYear($parsed['year']);
         }
     } catch (Exception $e) {
         // Date can not be parsed
         return false;
     }
     if ((strpos($this->_format, 'Y') !== false or strpos($this->_format, 'y') !== false) and !isset($parsed['year'])) {
         // Year expected but not found
         return false;
     }
     if (strpos($this->_format, 'M') !== false and !isset($parsed['month'])) {
         // Month expected but not found
         return false;
     }
     if (strpos($this->_format, 'd') !== false and !isset($parsed['day'])) {
         // Day expected but not found
         return false;
     }
     if ((strpos($this->_format, 'H') !== false or strpos($this->_format, 'h') !== false) and !isset($parsed['hour'])) {
         // Hour expected but not found
         return false;
     }
     if (strpos($this->_format, 'm') !== false and !isset($parsed['minute'])) {
         // Minute expected but not found
         return false;
     }
     if (strpos($this->_format, 's') !== false and !isset($parsed['second'])) {
         // Second expected  but not found
         return false;
     }
     // Date fits the format
     return true;
 }
Example #3
0
 /**
  * Defined by Postman_Zend_Validate_Interface
  *
  * Returns true if and only if $value is a floating-point value
  *
  * @param  string $value
  * @return boolean
  */
 public function isValid($value)
 {
     if (!is_string($value) && !is_int($value) && !is_float($value)) {
         $this->_error(self::INVALID);
         return false;
     }
     if (is_float($value)) {
         return true;
     }
     $this->_setValue($value);
     try {
         if (!Postman_Zend_Locale_Format::isFloat($value, array('locale' => $this->_locale))) {
             $this->_error(self::NOT_FLOAT);
             return false;
         }
     } catch (Postman_Zend_Locale_Exception $e) {
         $this->_error(self::NOT_FLOAT);
         return false;
     }
     return true;
 }