00001 <?php 00002 00027 require_once 'Zend/Validate/Abstract.php'; 00028 00029 00036 class Zend_Validate_Digits extends Zend_Validate_Abstract 00037 { 00038 const NOT_DIGITS = 'notDigits'; 00039 const STRING_EMPTY = 'stringEmpty'; 00040 const INVALID = 'digitsInvalid'; 00041 00047 protected static $_filter = null; 00048 00054 protected $_messageTemplates = array( 00055 self::NOT_DIGITS => "'%value%' contains not only digit characters", 00056 self::STRING_EMPTY => "'%value%' is an empty string", 00057 self::INVALID => "Invalid type given, value should be string, integer or float", 00058 ); 00059 00068 public function isValid($value) 00069 { 00070 if (!is_string($value) && !is_int($value) && !is_float($value)) { 00071 $this->_error(self::INVALID); 00072 return false; 00073 } 00074 00075 $this->_setValue((string) $value); 00076 00077 if ('' === $this->_value) { 00078 $this->_error(self::STRING_EMPTY); 00079 return false; 00080 } 00081 00082 if (null === self::$_filter) { 00083 require_once 'Zend/Filter/Digits.php'; 00084 self::$_filter = new Zend_Filter_Digits(); 00085 } 00086 00087 if ($this->_value !== self::$_filter->filter($this->_value)) { 00088 $this->_error(self::NOT_DIGITS); 00089 return false; 00090 } 00091 00092 return true; 00093 } 00094 00095 }