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', 
                            ) 
                        ), 
                    ),  
                ),
            )));
4

1 回答 1

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'
                        ),
                    )
                ),
            ),
        )));
于 2013-05-05T08:20:40.210 回答