[Validator] more strict e-mail validation regex

This commit is contained in:
Christian Flothmann 2015-06-03 23:17:06 +02:00
parent 418b28b464
commit 64910338ea
2 changed files with 2 additions and 3 deletions

View File

@ -24,8 +24,6 @@ use Symfony\Component\Validator\Exception\UnexpectedTypeException;
class EmailValidator extends ConstraintValidator class EmailValidator extends ConstraintValidator
{ {
/** /**
* isStrict
*
* @var bool * @var bool
*/ */
private $isStrict; private $isStrict;
@ -73,7 +71,7 @@ class EmailValidator extends ConstraintValidator
return; return;
} }
} elseif (!preg_match('/.+\@.+\..+/', $value)) { } elseif (!preg_match('/^.+\@\S+\.\S+$/', $value)) {
$this->buildViolation($constraint->message) $this->buildViolation($constraint->message)
->setParameter('{{ value }}', $this->formatValue($value)) ->setParameter('{{ value }}', $this->formatValue($value))
->setCode(Email::INVALID_FORMAT_ERROR) ->setCode(Email::INVALID_FORMAT_ERROR)

View File

@ -91,6 +91,7 @@ class EmailValidatorTest extends AbstractConstraintValidatorTest
array('example'), array('example'),
array('example@'), array('example@'),
array('example@localhost'), array('example@localhost'),
array('foo@example.com bar'),
); );
} }