如何以 zend 形式提供浮点数验证器?
以下是从表单中获取的代码段,
$debit_amount = new Zend_Form_Element_Text('debit_amount', array(
'label' => 'Debit_amount',
'value' => '',
'class' => 'text-size text',
'required' => true,
'tabindex' => '13',
'validators' => array(
array('Digits', false, array(
'messages' => array(
'notDigits' => "Invalid entry, ex. 10.00",
'digitsStringEmpty' => "",
))),
array('notEmpty', true, array(
'messages' => array(
'isEmpty' => 'Debit_amount can\'t be empty'
)
)),
),
'filters' => array('StringTrim'),
//'decorators' => $this->requiredElementDecorators,
//'description' => '<img src="' . $baseurl . '/images/star.png" alt="required" />',
));
$this->addElement($debit_amount);
当我尝试使用浮点数提交表单时,它会抛出错误“无效输入......”。它不验证浮点数。请提供建议。
Following is the piece of code which has been taken from form,
$debit_amount = new Zend_Form_Element_Text('debit_amount', array(
'label' => 'Debit_amount',
'value' => '',
'class' => 'text-size text',
'required' => true,
'tabindex' => '13',
'validators' => array(
array('Digits', false, array(
'messages' => array(
'notDigits' => "Invalid entry, ex. 10.00",
'digitsStringEmpty' => "",
))),
array('notEmpty', true, array(
'messages' => array(
'isEmpty' => 'Debit_amount can\'t be empty'
)
)),
),
'filters' => array('StringTrim'),
//'decorators' => $this->requiredElementDecorators,
//'description' => '<img src="' . $baseurl . '/images/star.png" alt="required" />',
));
$this->addElement($debit_amount);
When i try submit the form using floating number , it throws my error "Invalid Enter....". It does not validate floating point number. Kindly advice.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 Zend_Validate_Float:
Use Zend_Validate_Float:
您收到错误消息是因为
Digits
验证器仅验证数字。 Zend_Validate 文档:正如 @Zyava 所说,使用
Zend_Validate_Float
是正确的方法。You are getting the error message because the
Digits
validator only validates digits. There is a comment about it in the Zend_Validate documentation:As @Zyava says, using
Zend_Validate_Float
is the way to go.