Zend Validator用于带有负标记的数字

时间:2013-06-06 05:27:40

标签: php validation zend-framework

我使用zend框架和zend表单和验证器DIGIT,如下所示:

    $ZV_Digit=new Zend_Validate_Digits();
    $credit = new Zend_Form_Element_Text('credit');
    $credit->setLabel('current credit');
    $credit->setValidators(array($ZV_Digit));

但它没有传递负数并给出了这个错误:

'-4000' contains not only digit characters

我现在能做什么?

1 个答案:

答案 0 :(得分:6)

来自Zend Framework documentation

Note: Validating numbers
When you want to validate numbers or numeric values, 
be aware that this validator only validates digits.
This means that any other sign like a thousand separator
or a comma will not pass this validator.
In this case you should use Zend_Validate_Int or Zend_Validate_Float