Symfony2 - How to validate an email address in a controller

后端 未结 6 1474
走了就别回头了
走了就别回头了 2021-02-01 18:38

There is an email validator in symfony that can be used in a form: http://symfony.com/doc/current/reference/constraints/Email.html

My question is: How can I use this val

6条回答
  •  鱼传尺愫
    2021-02-01 19:01

    Another way - you may use egulias/EmailValidator bundle.

    composer require egulias/email-validator
    

    It can be used without container

        use Egulias\EmailValidator\EmailValidator;
        use Egulias\EmailValidator\Validation\RFCValidation;
        
        $validator = new EmailValidator();
        $validator->isValid("example@example.com", new RFCValidation());
    

    Also bundle can validate DNS with DNSCheckValidation

提交回复
热议问题