[ "Incorrect individual name %value%", "Incorrect individuals names %value%", ] ]; function __construct(array $options) { if ($options instanceof Zend_Config) { $options = $options->toArray(); } else if (!is_array($options)) { throw new Exception('Invalid options'); } if (!array_key_exists('elementId', $options)) { throw new Exception('elementId is undefined'); } $this->setElementId($options['elementId']); } /** * @param mixed $elementId * @return $this */ public function setElementId($elementId) { $this->_elementId = $elementId; return $this; } protected function _setMessageTemplate($errorsCount) { $this->_messageTemplates[self::INDIVIDUAL_NAME] = Qs_Translate::getPlural($this->_messages[self::INDIVIDUAL_NAME], $errorsCount); return $this; } public function isValid($value, $context = null) { $incorrectUsers = []; if (is_array($context[$this->_elementId])) { foreach ($context[$this->_elementId] as $value) { if (!$this->_isValidUserName($value)) { $incorrectUsers[] = $value['_' . $this->_elementId]; } } } else { if (!$this->_isValidUserName($context)) { $incorrectUsers[] = $context['_' . $this->_elementId]; } } if ($incorrectUsers) { $this->_setMessageTemplate(count($incorrectUsers)); $this->_error(self::INDIVIDUAL_NAME, implode(', ', $incorrectUsers)); return false; } return true; } protected function _isValidUserName($value) { if (!$value[$this->_elementId]) { $userNameString = $value['_' . $this->_elementId]; return preg_match('/(?^[a-zA-Z.-]+)\s(?[a-zA-Z.-\s]+)/', $userNameString); } else { return true; } } }