我在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
)
)
)
)));
答案 0 :(得分:1)
通过添加i
修饰符
/^[a-z0-9_.-]{1,50}+$/i
或明确允许大写字母:
/^[a-zA-Z0-9_.-]{1,50}+$/