[Validator] more strict e-mail validation regex
This commit is contained in:
parent
418b28b464
commit
64910338ea
@ -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)
|
||||||
|
@ -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'),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user