Using “.” for decimals in zend validator float

独自空忆成欢 提交于 2019-12-05 21:16:43

You can use a filter Zend_Filter LocalizedToNormalized to it will normalized you localized price according to the user's locale.

A typical price element would be like this one:

$price = new Zend_Form_Element_Text('price');
$price->setLabel('Price:')
      ->setRequired(true)
      ->setAttribs(array('required name' => 'price', 'maxlength' => '12'))
      ->addFilter('StripTags')
      ->addFilter('StringTrim')
      ->addFilter('pregReplace', array('match' => '/\s+/', 'replace' => ''))
      ->addFilter('LocalizedToNormalized')
      ->addValidator('stringLength', true, array(1, 12))
      ->addValidator('float', true, array('locale' => 'en_US'))
      ->addValidator('greaterThan', true, array('min' => 0));
$this->addElement($price);

Of course, you can improve it and add the validators/filters you need.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!