Zend framework2针对特定地址的电子邮件验证,例如gmail和阻止特定电子邮件地址

时间:2013-05-04 19:39:08

标签: zend-framework2

我有电子邮件地址的输入过滤器,我想限制特定的电子邮件服务提供商,请帮我解决此问题。

我还有一个表单,我想允许该受限制的电子邮件服务提供商仅在此处注册。请告诉我如何限制一个特定的电子邮件服务提供商,另一种形式只允许一个特定的电子邮件服务提供商。

提前致谢

$inputFilter->add($factory->createInput(array(
                'name'     => 'email',
                'required' => true,
                'filters'  => array(
                    array('name' => 'StripTags'),
                    array('name' => 'StringTrim'),
                ),
                'validators' => array(
                    array(
                        'name'    => 'EmailAddress',
                        'options' => array(
                            'messages' => array( 
                                'emailAddressInvalidFormat' => 'Email address format is not invalid', 
                            )
                        ),
                    ),
                    array ( 
                        'name' => 'NotEmpty', 
                        'options' => array( 
                            'messages' => array( 
                                'isEmpty' => 'Email address is required', 
                            ) 
                        ), 
                    ),  
                ),
            )));

1 个答案:

答案 0 :(得分:0)

添加正则表达式验证程序:

        $inputFilter->add($factory->createInput(array(
            'name'     => 'email',
            'required' => true,
            'filters'  => array(
                array('name' => 'StripTags'),
                array('name' => 'StringTrim'),
            ),
            'validators' => array(
                array(
                    'name'    => 'EmailAddress',
                    'options' => array(
                        'messages' => array(
                            'emailAddressInvalidFormat' => 'Email address format is not invalid',
                        )
                    ),
                ),
                array (
                    'name' => 'NotEmpty',
                    'options' => array(
                        'messages' => array(
                            'isEmpty' => 'Email address is required',
                        )
                    ),
                ),
                array(
                    'name' => 'Regex',
                    'options' => array(
                        'pattern' => '/@gmail.com$/',
                        'messages' => array(
                            'regexNotMatch' => 'You must have a gmail.com email address'
                        ),
                    )
                ),
            ),
        )));