From 64910338ea4ca621da6832058ebab05ce44961d9 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Wed, 3 Jun 2015 23:17:06 +0200 Subject: [PATCH] [Validator] more strict e-mail validation regex --- .../Component/Validator/Constraints/EmailValidator.php | 4 +--- .../Validator/Tests/Constraints/EmailValidatorTest.php | 1 + 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/Validator/Constraints/EmailValidator.php b/src/Symfony/Component/Validator/Constraints/EmailValidator.php index 8d3a7c5104a2..903ce5971166 100644 --- a/src/Symfony/Component/Validator/Constraints/EmailValidator.php +++ b/src/Symfony/Component/Validator/Constraints/EmailValidator.php @@ -24,8 +24,6 @@ class EmailValidator extends ConstraintValidator { /** - * isStrict - * * @var bool */ private $isStrict; @@ -73,7 +71,7 @@ public function validate($value, Constraint $constraint) return; } - } elseif (!preg_match('/.+\@.+\..+/', $value)) { + } elseif (!preg_match('/^.+\@\S+\.\S+$/', $value)) { $this->buildViolation($constraint->message) ->setParameter('{{ value }}', $this->formatValue($value)) ->setCode(Email::INVALID_FORMAT_ERROR) diff --git a/src/Symfony/Component/Validator/Tests/Constraints/EmailValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/EmailValidatorTest.php index 0361333fdc16..7e7a5cc70f0d 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/EmailValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/EmailValidatorTest.php @@ -91,6 +91,7 @@ public function getInvalidEmails() array('example'), array('example@'), array('example@localhost'), + array('foo@example.com bar'), ); }