Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Look at <a href="https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Validator/Constraints/EmailValidator.php#L30-L32" rel="nofollow">the source</a> of the validator: if an empty string or null is passed, it does nothing. In other words, empty values will always succeed.</p> <p>So yep, it's expected behavior though there's a ticket about changing it.</p> <pre><code>&lt;?php /** * @author Bernhard Schussek &lt;[...]&gt; * * @api */ class EmailValidator extends ConstraintValidator { /** * {@inheritDoc} */ public function validate($value, Constraint $constraint) { if (null === $value || '' === $value) { return; } if (!is_scalar($value) &amp;&amp; !(is_object($value) &amp;&amp; method_exists($value, '__toString'))) { throw new UnexpectedTypeException($value, 'string'); } $value = (string) $value; $valid = filter_var($value, FILTER_VALIDATE_EMAIL); if ($valid) { $host = substr($value, strpos($value, '@') + 1); // Check for host DNS resource records if ($valid &amp;&amp; $constraint-&gt;checkMX) { $valid = $this-&gt;checkMX($host); } elseif ($valid &amp;&amp; $constraint-&gt;checkHost) { $valid = $this-&gt;checkHost($host); } } if (!$valid) { $this-&gt;context-&gt;addViolation($constraint-&gt;message, array('{{ value }}' =&gt; $value)); } } // ... } </code></pre> <p>You'll need to use a combination of <code>NotBlank</code> and <code>Email</code></p> <pre><code>&lt;?php use Symfony\Component\Validator\Constraints as Assert; $emailValidator = new Assert\Email(); $emailValidator-&gt;message = 'Invalid email address'; $validator-&gt;validateValue($the_email, array( new Assert\NotBlank(), $emailValidator, )); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload