Hi,
caution, there is a bug in that diff: the elseif condition will always be true
as it assigns the value 'int' to the variable $type which should always
succeed. [Hint: this is a reason to state the constant first in comparisons,
because "'int' = $type" is not a valid assignment].
A second (but minor thing): I'd rather use typecasts than regexps for this kind
of checking, as regular expressions carry the overhead of invoking the regexp
engine.
A corrected version of the diff is below:
Index: NumberValidator.class.php
===================================================================
--- NumberValidator.class.php (revision 265)
+++ NumberValidator.class.php (working copy)
@@ -90,7 +90,20 @@
$value = (float) $value;
}
+ elseif ('int' == $type) {
+ // cast the value first to int and then back to string to
enforce
+ // a string comparison and override implicit conversion
rules.
+ if ((string)(int)$value != (string)$value) {
+
+ $error = $this->getParameter('type_error');
+
+ return false;
+ }
+ // cast our value to an int
+ $value = (int) $value;
+ }
+
$min = $this->getParameter('min');
if ($min != null && $value < $min)
--------------------------------------------------------------------------
> Steven Weiß wrote:
>
>> 3) improvement of NumberValidator
>> http://trac.agavi.org/trac.cgi/ticket/56
>
> I would take this a bit further and make the regexp accept negative
> integers too: http://veikkomakinen.com/agavi/NumberValidator.diff.txt.
> There is a 'min' parameter to make the validator accept only positive
> numbers.
>
>
> -veikko
>
> P.S. I do not have commit access to agavi svn (yet), so these changes
> aren't in the official version (yet).
>
> _______________________________________________
> agavi-dev mailing list
> [email protected]
> http://labworkz.com/cgi-bin/mailman/listinfo/agavi-dev
regards,
fg
--
Felix Gilcher
Head of IT Development
Exozet Berlin GmbH
Rotherstraße 20
10245 Berlin
_______________________________________________
agavi-dev mailing list
[email protected]
http://labworkz.com/cgi-bin/mailman/listinfo/agavi-dev