symfony的3使用“严格” =>在电子邮件验证字段真

问题描述 投票:1回答:2

我想补充'strict' => true以电子邮件形式建设https://symfony.com/doc/3.3/reference/constraints/Email.html#strict输入验证

为什么?因为正常的电子邮件验证允许无效的电子邮件前。 test@test过去了!

我试过,但我得到的错误(The option "strict" does not exist. Defined options are: "action", "allow_extra_fields", "attr", ... )

代码这样的:

public function buildForm(FormBuilderInterface $builder, array $options) :void
{
     $builder
     ->add('name', TextType::class, [ 'label' => 'Name' ])
     ->add('email', EmailType::class, [
           'label' => 'Email', 
           'strict' => true ]  <<<<< not work
     )
     ->add('subject', ChoiceType::class, [ 'label' => 'Subject',
     ...
forms symfony validation email
2个回答
2
投票

尝试注册像下面验证约束:

$builder
     ->add('name', TextType::class, [ 'label' => 'Name' ])
     ->add('email', EmailType::class, [
           'label' => 'Email', 
           'constraints' => array(
               new Email(array('strict'=>true)),
            )
       )

0
投票

除了增加'strict' => trueEmail的约束选项,也有在Symfony框架的配置,使其能够在默认情况下所有Email约束的设置。见strict_email configuration in the Symfony docs v3.4

为symfony1.2> = 4.1的配置选项strict_email已弃用so use email_validation_mode instead

© www.soinside.com 2019 - 2024. All rights reserved.