ZF-8001: Zend_Validate_Int ignores a locale param
Description
$validator = new Zend_Validate_Int(); $value = '23'; if ($validator->isValid($value)) { echo('ok'); } else { echo('not ok'); }
$validator = new Zend_Validate_Int("en_NZ"); $value = '23'; if ($validator->isValid($value)) { echo('ok'); } else { echo('not ok'); }
in the both samples return "ok", but in the second sample ignores a user locale parameter (en_NZ). I can attach a Xdebug trace file is necessary.
Solution:
... public function __construct($locale = null) { $this->setLocale($locale); } ... public function setLocale($locale = null) {
if (!is_null($locale)) {
require_once 'Zend/Locale.php';
$this->_locale = Zend_Locale::findLocale($locale);
} else {
$this->_locale = $locale;
}
return $this;
}
...
Comments
Posted by Thomas Weidner (thomas) on 2009-10-01T23:47:48.000+0000
Check your installation. Locale usage is available since 1.8. The code you gave is available in 1.9.
Btw: For Int detection "23" works always... there is no localized difference between "23" in french or german and "23" in english.
Posted by Tiago Seabra (tseabra) on 2012-06-12T09:42:42.000+0000
On ZF 1.11.11 i tried this
$value = '9'; $validator = new Zend_Validate_Int('en_EN'); echo 'int ---> '; echo ($validator->isValid($value))?'ok':'not ok'; echo '
'; $validator = new Zend_Validate_Int("en_IN"); echo 'int IN ---> '; echo ($validator->isValid($value))?'ok':'not ok';
---------------output int ---> ok int IN ---> not ok