示例#1
0
 /**
  * Ensures that the validator follows expected behavior
  *
  * @return void
  */
 public function testBasic()
 {
     $valuesExpected = array(array(1, false), array(0x1, false), array(0x123, true), array('1', true), array('abc123', true), array('ABC123', true), array('1234567890abcdef', true), array('g', false), array('1.2', false));
     foreach ($valuesExpected as $element) {
         $this->assertEquals($element[1], $this->_validator->isValid($element[0]));
     }
 }
 protected function doClean($value)
 {
     $zfValidator = new Zend_Validate_Hex();
     if (!$zfValidator->isValid($value)) {
         throw new sfValidatorError($this, 'invalid');
     }
     return $value;
 }
 public static function validateHex($validator, $value, $arguments)
 {
     if (!in_array(strlen($value), array(3, 6))) {
         throw new sfValidatorError($validator, 'invalid');
     }
     $zfValidator = new Zend_Validate_Hex();
     if (!$zfValidator->isValid($value)) {
         throw new sfValidatorError($validator, 'invalid');
     }
     return $value;
 }
 public function hexAction()
 {
     $v = new Zend_Validate_Hex();
     $string = 'AAP';
     if ($v->isValid($string)) {
         echo "AA eh hexadecimal";
     } else {
         echo "{$string} nao eh hexadecimal";
         $erros = $v->getMessages();
         print_r($erros);
     }
     exit;
 }
示例#5
0
文件: HexTest.php 项目: travisj/zf
 /**
  * @ZF-4352
  */
 public function testNonStringValidation()
 {
     $this->assertFalse($this->_validator->isValid(array(1 => 1)));
 }
示例#6
0
文件: HexTest.php 项目: lortnus/zf1
 /**
  * Ensures that getMessages() returns expected default value
  *
  * @return void
  */
 public function testGetMessages()
 {
     $this->assertEquals(array(), $this->_validator->getMessages());
 }
示例#7
0
 /**
  * Returns TRUE if value is a valid hexadecimal format, FALSE
  * otherwise.
  *
  * @deprecated since 0.8.0
  * @param      mixed $value
  * @return     boolean
  */
 public static function isHex($value)
 {
     require_once 'Zend/Validate/Hex.php';
     $validator = new Zend_Validate_Hex();
     return $validator->isValid($value);
 }