'You have used unallowed symbols. Please note: the allowed ones are a-z, A-Z, 0-9, "-", "_", "."', self::NOT_UNIQUE => 'Alias must be unique' ); protected $_pattern = '/^[-_a-zA-Z0-9\.]+$/'; protected $_uniqueValidator; /** * Sets validator options * Accepts the following option keys (only for unique validation, default use Qs_Validate_Unique): * 'table' => Qs_Db_Table object(current table) * 'column' => column for validation * 'current' => current value key * 'options' => array options for Qs_Validate_Unique * 'uniqueValidator' => another object validator for validating the unique * * @todo * example $form->alias->addValidator( * 'Alias', * false, * array( * array( * 'table' => $this->dataObj->table, * 'column' => 'alias', * 'current' => $this->dataObj->getPrimaryKey() * ) * ) * ); * * @param array $options * @param bool $validateUnique If validate value for unique * @return void */ public function __construct($options, $validateUnique = true) { if (array_key_exists('pattern', $options)) { $this->_setPattern($options['pattern']); unset($options['pattern']); } if ($validateUnique) { if (array_key_exists('uniqueValidator', $options)) { $this->setUniqueValidator($options['uniqueValidator']); } elseif (array_key_exists('table', $options) && array_key_exists('column', $options)) { if (!$options['table'] instanceof Qs_Db_Table) { throw new Zend_Validate_Exception('"table" options must be instance of Qs_Db_Table'); } $uniqueValidator = new Qs_Validate_Unique( $options['table'], $options['column'], (!empty($options['current'])?$options['current']:null), (!empty($options['options'])?$options['options']:array()) ); $this->setUniqueValidator($uniqueValidator); } } } /** * Set validator object for unique validations * * @param Zend_Validate_Abstract $validator * @return Qs_Validate_Alias */ public function setUniqueValidator($validator) { if (!$validator instanceof Zend_Validate_Abstract) { throw new Zend_Validate_Exception('Unique validator must be instance of Zend_Validate_Abstract'); } $this->_uniqueValidator = $validator; return $this; } public function setPattern($pattern) { $this->_pattern = $parretn; return $this; } public function isValid($value) { $this->_setValue($value); $regexValidator = new Zend_Validate_Regex(array('pattern' => $this->_pattern)); $isValid = true; if (!$regexValidator->isValid($value)) { $this->_error(self::NOT_MATCH); $isValid = false; } if (!empty($this->_uniqueValidator)) { if (!$this->_uniqueValidator->isValid($value)) { $this->_error(self::NOT_UNIQUE); $isValid = false; } } return $isValid; } }