"Your password should be at least %d characters and have at least %d numbers.", ]; public function __construct($options = []) { if ($options instanceof Zend_Config) { $options = $options->toArray(); } if (array_key_exists('minLength', $options) && $options['minLength'] > 0) { $this->_minLength = intval($options['minLength']); } if (array_key_exists('minNumbersCount', $options) && $options['minNumbersCount'] > 0) { $this->_minNumbersCount = intval($options['minNumbersCount']); } if ($this->_minNumbersCount >= $this->_minLength) { throw new Qs_Exception('Wrong password configuration options.'); } } public function isValid($value) { $this->_setValue($value); $length = strlen($value); $numbersCount = strlen(preg_replace('/[^\d]+/', '', $value)); if ($length < $this->_minLength || $numbersCount < $this->_minNumbersCount) { $this->_error(self::NOT_SECURE); return false; } return true; } protected function _createMessage( $messageKey, $value ) { $message = parent::_createMessage( $messageKey, $value ); $message = sprintf($message, $this->_minLength, $this->_minNumbersCount); return $message; } }