'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 * * Example: * * $form->alias->addValidator( * 'Alias', * false, * array( * array( * 'table' => new Qs_Db_Table('table'), * 'column' => 'alias', * 'current' => $this->_getData('id'), * 'options' => array() //Additional options for default unique validator * ) * ) * ); * * @param array $options * @param bool $validateUnique If validate value for unique */ 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'); } if (!empty($options['current'])) { trigger_error('current - the option is deprecated for alias validator, please use currentId'); $options['currentId'] = $options['current']; } $uniqueValidator = new Qs_Validate_Unique( $options['table'], $options['column'], (!empty($options['currentId'])?$options['currentId']: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 = $pattern; return $this; } public function getPattern() { return $this->_pattern; } public function isValid($value) { $this->_setValue($value); $regexValidator = new Zend_Validate_Regex(array('pattern' => $this->getPattern())); $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; } }