Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Simplified EmailValidator using native PHP validation function.
  • Loading branch information
mweimerskirch committed Feb 24, 2011
commit 5f0d83662cad94a10eb68f648432a5e3ebb49ab3
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

class EmailValidator extends ConstraintValidator
{
const PATTERN = '/^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i';

public function isValid($value, Constraint $constraint)
{
Expand All @@ -31,7 +30,7 @@ public function isValid($value, Constraint $constraint)

$value = (string)$value;

if (!preg_match(self::PATTERN, $value)) {
if (!filter_var($value, FILTER_VALIDATE_EMAIL)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

filter_var isn't compliant with the email specification, but I guess it's still better than the old pattern, until someone has the time to integrate that other email parsing lib..

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its not necessarily better than the old pattern (although thats a very bad one). The disadvantage of FILTER_VALIDATE_EMAIL is that you can change the pattern through an ini constant.

$this->setMessage($constraint->message, array('{{ value }}' => $value));

return false;
Expand Down