00001 <?php 00002 00027 require_once 'Zend/Validate/Abstract.php'; 00028 00029 00036 class Zend_Validate_Hex extends Zend_Validate_Abstract 00037 { 00038 const INVALID = 'hexInvalid'; 00039 const NOT_HEX = 'notHex'; 00040 00046 protected $_messageTemplates = array( 00047 self::INVALID => "Invalid type given, value should be a string", 00048 self::NOT_HEX => "'%value%' has not only hexadecimal digit characters" 00049 ); 00050 00059 public function isValid($value) 00060 { 00061 if (!is_string($value) && !is_int($value)) { 00062 $this->_error(self::INVALID); 00063 return false; 00064 } 00065 00066 $this->_setValue($value); 00067 if (!ctype_xdigit((string) $value)) { 00068 $this->_error(self::NOT_HEX); 00069 return false; 00070 } 00071 00072 return true; 00073 } 00074 00075 }