如何在zf2中验证zend表单?

时间:2014-05-06 13:51:35

标签: php zend-framework2 zend-form zend-validate

我在zend framework2中创建了一个表单,但我不能添加大写字母如何在zf2中验证资本A到Z?这是我的代码:

if(!$this->inputFilter)
    {
        $inputFilter = new InputFilter();
        $factory = new InputFactory();
        $inputFilter->add($factory->createInput(array(
            'name' => 'username',
            'required'=>true,
            'filters'=> array(
                array('name'=>'StripTags'),
                array('name'=>'StringTrim')
            ),
            'validators'=>array(
                array('name'=>'Regex',
                    'options'=> array(
                        'pattern' => '/^[a-z0-9_.-]{1,50}+$/' // contain only a to z 0 to 9 underscore, hypen and dot and min 1 characters max 50
                    )
                )
            )
        )));

1 个答案:

答案 0 :(得分:1)

通过添加i修饰符

,将您的模式更改为不区分大小写
/^[a-z0-9_.-]{1,50}+$/i

或明确允许大写字母:

/^[a-zA-Z0-9_.-]{1,50}+$/