PHP Classes

Bug in numeric validations

Recommend this page to a friend!

      PHP Forms Class with HTML Generator and JavaScript Validation  >  PHP Forms Class with HTML Generator and JavaScript Validation package blog  >  How to Show Google Ma...  >  All threads  >  Bug in numeric validations  >  (Un) Subscribe thread alerts  
Subject:Bug in numeric validations
Summary:Numbers with leading zeros are not properly validated
Messages:2
Author:Matías montes
Date:2007-03-02 14:32:53
Update:2007-03-02 18:39:18
 

  1. Bug in numeric validations   Reply   Report abuse  
Picture of Matías montes Matías montes - 2007-03-02 14:32:54
Numbers with leading zeros such as: 011, 0066, etc should be considered valid numeric values but they fail numeric validations (integer, float, etc)

solution:
I replaced line 2240 (the one that creates the Javascript Validation for ValidateAsInteger) for:

$t = $field_value.".match(/^(0+)?(.*)/g) && parseInt(".$field_value.",10).toString()!=(RegExp.$2.length == 0 ? '0' : RegExp.$2)";

Explanation:
The first regular expression will always match, but I need it to save the non-zero values in RegExp.$2
Then, instead of checking the integer value of the field against its current value, I check it against the zero trimmed value.
The conditional verification with the expression length is for the value '0' (or '00' or '000', etc) which should be considered a valid integer.

  2. Re: Bug in numeric validations   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2007-03-02 18:39:18 - In reply to message 1 from Matías montes
The integer and float validations work as intended. If you need to accept values with leading zeros, use an appropriate regular expression instead.