Validates that a value is a valid email address. The underlying value is cast to a string before being validated.
.. configuration-block:: .. code-block:: php-attributes // src/Entity/Author.php namespace App\Entity; use Symfony\Component\Validator\Constraints as Assert; class Author { #[Assert\Email( message: 'The email {{ value }} is not a valid email.', )] protected string $email; } .. code-block:: yaml # config/validator/validation.yaml App\Entity\Author: properties: email: - Email: message: The email "{{ value }}" is not a valid email. .. code-block:: xml <!-- config/validator/validation.xml --> <?xml version="1.0" encoding="UTF-8" ?> <constraint-mapping xmlns="http://symfony.com/schema/dic/constraint-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/constraint-mapping https://symfony.com/schema/dic/constraint-mapping/constraint-mapping-1.0.xsd"> <class name="App\Entity\Author"> <property name="email"> <constraint name="Email"> <option name="message">The email "{{ value }}" is not a valid email.</option> </constraint> </property> </class> </constraint-mapping> .. code-block:: php // src/Entity/Author.php namespace App\Entity; use Symfony\Component\Validator\Constraints as Assert; use Symfony\Component\Validator\Mapping\ClassMetadata; class Author { // ... public static function loadValidatorMetadata(ClassMetadata $metadata): void { $metadata->addPropertyConstraint('email', new Assert\Email([ 'message' => 'The email "{{ value }}" is not a valid email.', ])); } }
type: string
default: This value is not a valid email address.
This message is shown if the underlying data is not a valid email address.
You can use the following parameters in this message:
Parameter | Description |
---|---|
{{ value }} |
The current (invalid) value |
{{ label }} |
Corresponding form field label |
type: string
default: html5
This option defines the pattern used to validate the email address. Valid values are:
html5
uses the regular expression of the HTML5 email input element, except it enforces a tld to be present.html5-allow-no-tld
uses exactly the same regular expression as the HTML5 email input element, making the backend validation consistent with the one provided by browsers.strict
validates the address according to RFC 5322 using the egulias/email-validator library (which is already installed when using :doc:`Symfony Mailer </mailer>`; otherwise, you must install it separately).
Tip
The possible values of this option are also defined as PHP constants of
:class:`Symfony\\Component\\Validator\\Constraints\\Email`
(e.g. Email::VALIDATION_MODE_STRICT
).
The default value used by this option is set in the :ref:`framework.validation.email_validation_mode <reference-validation-email_validation_mode>` configuration option.