|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00025 require_once 'Zend/Validate/Abstract.php'; 00026 00033 class Zend_Validate_Digits extends Zend_Validate_Abstract 00034 { 00035 const NOT_DIGITS = 'notDigits'; 00036 const STRING_EMPTY = 'digitsStringEmpty'; 00037 const INVALID = 'digitsInvalid'; 00038 00044 protected static $_filter = null; 00045 00051 protected $_messageTemplates = array( 00052 self::NOT_DIGITS => "'%value%' contains characters which are not digits; but only digits are allowed", 00053 self::STRING_EMPTY => "'%value%' is an empty string", 00054 self::INVALID => "Invalid type given, value should be string, integer or float", 00055 ); 00056 00065 public function isValid($value) 00066 { 00067 if (!is_string($value) && !is_int($value) && !is_float($value)) { 00068 $this->_error(self::INVALID); 00069 return false; 00070 } 00071 00072 $this->_setValue((string) $value); 00073 00074 if ('' === $this->_value) { 00075 $this->_error(self::STRING_EMPTY); 00076 return false; 00077 } 00078 00079 if (null === self::$_filter) { 00080 require_once 'Zend/Filter/Digits.php'; 00081 self::$_filter = new Zend_Filter_Digits(); 00082 } 00083 00084 if ($this->_value !== self::$_filter->filter($this->_value)) { 00085 $this->_error(self::NOT_DIGITS); 00086 return false; 00087 } 00088 00089 return true; 00090 } 00091 }