Zend Framework 2 - 整数形式验证 [英] Zend Framework 2 - Integer Form Validation
本文介绍了Zend Framework 2 - 整数形式验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我遇到了以下问题.我写了(基于教程)一个表单验证.文本字段工作正常,但整数字段表现奇怪.
I've got the following problem. I wrote (based on the tutorial) a form validation. The text fields work just fine but the integer field behave odd.
这是我的验证器:
$inputFilter->add($factory->createInput(array(
'name' => 'zip',
'required' => false,
'filters' => array(
array('name' => 'Int'),
),
)));
它像其他过滤器一样位于我的 Entity.php 中.奇怪的是,当我将它设置为 true
时,它甚至不接受字符串,而是忽略了 required
.我尝试将 Int
替换为 Digits
然后导致表单接受 required
但仍然接受字符串.
It lies within my Entity.php like the other filters. The odd thing is that this one accepts not even a string but ignores the required
when I set it to true
. I tried to replace Int
with Digits
which then causes the form to accept required
but still accepts strings.
有什么想法吗?谢谢!
推荐答案
尝试使用 在验证器之间:
Try using the Between validator:
$inputFilter->add($factory->createInput(array(
'name' => 'zip',
'required' => true,
'filters' => array(
array('name' => 'Int'),
),
'validators' => array(
array(
'name' => 'Between',
'options' => array(
'min' => 1,
'max' => 1000,
),
),
),
)));
这篇关于Zend Framework 2 - 整数形式验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文