ZF-9293: Wrong behavior in Zend_Validate_Int and Zend_Validate_Float when locale is present.

Issue Type: Bug Created: 2010-02-28T14:40:01.000+0000 Last Updated: 2010-04-26T11:44:44.000+0000 Status: Resolved Fix version(s): - 1.10.4 (28/Apr/10)

Reporter: Leandro Rodrigues Chaves (leandrorc) Assignee: Thomas Weidner (thomas) Tags: - Zend_Validate

Related issues: Attachments:


When locale is present, isValid() shouldn't test using 'en' locale also. A example of this inconsistency is:

<pre class="highlight">
//consider Zend_Locale is already in Zend_Registry and it's 'pt_BR'
$number = $_POST['VALUE_IN_BRL'] // Value must be in Brazil's currency format, but let's suppose user typed 2,500.99 ('en' format)
$validate = new Zend_Validate_Float();
   //get number from localized string and save it to database
   $number = Zend_Locale_Format::getNumber($number);
   $msg = 'Enter the correct value!'

In addition to wrong behavior (2,500.99 is not valid in my application), i get this error:

Uncaught exception 'Zend_Locale_Exception' with message 'No localized value in 2,500.99 found, or the given number does not match the localized format' in path_to_zf\library\Zend\Locale\Format.php:247


Posted by Benjamin-Timm Broich (chameleon) on 2010-03-05T02:03:01.000+0000

<pre class="highlight">
$number = '1.5';
//$number   = '1,5'; // <- correct value for de_DE

$locale = new Zend_Locale('de_DE');
$validate = new Zend_Validate_Float($locale);

   echo Zend_Locale_Format::getNumber($number, array('locale' => $locale));
   // Throws Exception: No localized value in 1.5 found, or the given number does not match the localized format
   echo 'Wrong number or format';

One of my co-workers noticed me about the above mentioned code thats not working. Its still checking against the "en" locale, instaed of checking against the given de_DE locale.

I think that it's not necessary to check against the english locale if another locale (in this case de_DE) is given?!

Posted by Benjamin-Timm Broich (chameleon) on 2010-03-05T02:08:19.000+0000

Additionally to my comment above:

As we can see, the Float Validator always checks for the english locale.

<pre class="highlight">
class Zend_Validate_Float extends Zend_Validate_Abstract
    public function isValid($value)
                if (!Zend_Locale_Format::isFloat($value, array('locale' => 'en')) && // <- not needed if $this->_locale defined???
                    !Zend_Locale_Format::isFloat($value, array('locale' => $this->_locale))) {
                    return false;

Posted by Leandro Rodrigues Chaves (leandrorc) on 2010-03-05T03:29:51.000+0000

Exactly Benjamin! Same with Zend_Validate_Int. Another example why isValid() shouldn't test against 'en' could be in a financial test, when students must type the number format of many countries and the application must validate this.

Posted by Thomas Weidner (thomas) on 2010-03-05T14:53:11.000+0000

Reducing from critical to major. The inclusion of EN was forced by the core team despite my negative response to this request. Has to be discussed with team members before changing this in my eyes errorous behaviour.

Posted by Thomas Weidner (thomas) on 2010-03-27T14:31:45.000+0000

Not reproducable for Zend_Validate_Int. There is no relation to "en" within the Int validator.

Posted by Thomas Weidner (thomas) on 2010-04-26T11:44:44.000+0000

Closing as not reproduceable

Wether Int nor Float have a fixed "en" locale as mentioned. Both validators do not validate localized "en" numbers when another locale is given within or after the mentioned release

Have you found an issue?

See the Overview section for more details.


© 2006-2018 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.