Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/lib/zend/Zend/Validate/Alnum.php
Go to the documentation of this file.
00001 <?php
00025 require_once 'Zend/Validate/Abstract.php';
00026 
00033 class Zend_Validate_Alnum extends Zend_Validate_Abstract
00034 {
00035     const INVALID      = 'alnumInvalid';
00036     const NOT_ALNUM    = 'notAlnum';
00037     const STRING_EMPTY = 'alnumStringEmpty';
00038 
00045     public $allowWhiteSpace;
00046 
00052     protected static $_filter = null;
00053 
00059     protected $_messageTemplates = array(
00060         self::INVALID      => "Invalid type given, value should be float, string, or integer",
00061         self::NOT_ALNUM    => "'%value%' contains characters which are non alphabetic and no digits",
00062         self::STRING_EMPTY => "'%value%' is an empty string",
00063     );
00064 
00071     public function __construct($allowWhiteSpace = false)
00072     {
00073         if ($allowWhiteSpace instanceof Zend_Config) {
00074             $allowWhiteSpace = $allowWhiteSpace->toArray();
00075         }
00076 
00077         if (is_array($allowWhiteSpace)) {
00078             if (array_key_exists('allowWhiteSpace', $allowWhiteSpace)) {
00079                 $allowWhiteSpace = $allowWhiteSpace['allowWhiteSpace'];
00080             } else {
00081                 $allowWhiteSpace = false;
00082             }
00083         }
00084 
00085         $this->allowWhiteSpace = (boolean) $allowWhiteSpace;
00086     }
00087 
00093     public function getAllowWhiteSpace()
00094     {
00095         return $this->allowWhiteSpace;
00096     }
00097 
00104     public function setAllowWhiteSpace($allowWhiteSpace)
00105     {
00106         $this->allowWhiteSpace = (boolean) $allowWhiteSpace;
00107         return $this;
00108     }
00109 
00118     public function isValid($value)
00119     {
00120         if (!is_string($value) && !is_int($value) && !is_float($value)) {
00121             $this->_error(self::INVALID);
00122             return false;
00123         }
00124 
00125         $this->_setValue($value);
00126 
00127         if ('' === $value) {
00128             $this->_error(self::STRING_EMPTY);
00129             return false;
00130         }
00131 
00132         if (null === self::$_filter) {
00136             require_once 'Zend/Filter/Alnum.php';
00137             self::$_filter = new Zend_Filter_Alnum();
00138         }
00139 
00140         self::$_filter->allowWhiteSpace = $this->allowWhiteSpace;
00141 
00142         if ($value != self::$_filter->filter($value)) {
00143             $this->_error(self::NOT_ALNUM);
00144             return false;
00145         }
00146 
00147         return true;
00148     }
00149 
00150 }
 All Data Structures Namespaces Files Functions Variables Enumerations