简体   繁体   English

@之后的PHP Symfony电子邮件表单验证

[英]PHP Symfony email form validation after @

With my form builder I have an email field set up like this: 使用我的表单构建器,我可以像这样设置电子邮件字段:

       ->add('email', 'email', (array(
            'label'              => 'correo electrónico',
            'translation_domain' => 'SonataUserBundle',
            'attr' => array(
                'placeholder' => 'correo electrónico',
            ),
        )))

So lets say a user enters his value in the email field: 因此,假设用户在电子邮件字段中输入了他的值:

test - I get message to include @. Everything is fine here
test@ - it asks me to enter the following part of @. Everything is fine
test@ttt - he thinks this is a valid email and creates a user.

Instead it should give an error of an invalid email.. It should only accept atleast with .com or something... Is it possible to do in formbuilder? 相反,它应该给出无效电子邮件的错误。它应该只接受带有.com或类似符号的atleast。可以在formbuilder中进行吗? I want to make this in less code, js, as possible.. 我想用更少的代码js来做到这一点。

The EmailType field is a text field that is rendered using the HTML5 tag. EmailType字段是使用HTML5标签呈现的文本字段。 So it is validated by a browser only. 因此,仅通过浏览器进行验证。 You should validate this field using Email Validation Constraint 您应该使用“ 电子邮件验证约束”来验证此字段

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM