3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
10 namespace Zend\Validator
;
12 class Hex
extends AbstractValidator
14 const INVALID
= 'hexInvalid';
15 const NOT_HEX
= 'notHex';
18 * Validation failure message template definitions
22 protected $messageTemplates = array(
23 self
::INVALID
=> "Invalid type given. String expected",
24 self
::NOT_HEX
=> "The input contains non-hexadecimal characters",
28 * Returns true if and only if $value contains only hexadecimal digit characters
30 * @param string $value
33 public function isValid($value)
35 if (!is_string($value) && !is_int($value)) {
36 $this->error(self
::INVALID
);
40 $this->setValue($value);
41 if (!ctype_xdigit((string) $value)) {
42 $this->error(self
::NOT_HEX
);