"'%s' must contain one or multiple valid email addresses.", self::DUPLICATE => "'%s': you cannot enter an email address more than once.", ); /** * * emails separator * * @var string */ protected $_separator = ','; /** * * set emails separator * * @param string $separator * * @return $this */ public function setSeparator($separator) { $this->_separator = $separator; return $this; } /** * * get emails separator * * @return string */ public function getSeparator() { return $this->_separator; } /** * * checks if the variable contains a valid email address * * @return bool return true if the validation is successful */ public function isValid() { $separator = $this->getSeparator(); $value = $this->getValue(); $emails = array_map('trim', (array)explode($separator, $value)); $duplicates = array_count_values($emails); foreach ($emails as $email) { parent::setValue( trim($email)); if (!parent::isValid()) { $this->setMessage($this->_messages[self::NOT_VALID]); return false; } if ($duplicates[$email] > 1) { $this->setMessage($this->_messages[self::DUPLICATE]); return false; } } return true; } }