Re: cvs: pear /Validate Validate.php

From: Date: Wed, 29 May 2002 09:31:09 +0000
Subject: Re: cvs: pear /Validate Validate.php
References: 1 2  Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-4237@lists.php.net to get a copy of this message
On Wed, 29 May 2002 11:05:15 +0200 Bertrand Mansion <bmansion@wanadoo.fr> wrote: > le 29/05/02 10:29, Tomas V.V.Cox à cox@idecnet.com a écrit : > > >> Wouldn't it be better if you split the number method into integer > >and float> with both minus numbers accepted ? > >> > > > > Do you think is really necessary? > > > > - integer validation: Validate::number($number) > > - float validation: Validate::number($number, '.', 2) > > // (number, decimal char, precition) > > > > If you want to add range validation (let's say between 8 and 12) > > just: > > > > - integer validation: Validate::number($number, null, null, 8, 12) > > - float validation: Validate::number($number, '.', 2, 8, 12) > > Remember an integer or a float can also be negative. If you add this > as a parameter, it can become difficult to remember the parameters > order. function number($number, $decimal = null, $dec_prec = null, $min = null, $max = null) { $dec_prec = $dec_prec ? "{1,$dec_prec}" : '+'; $dec_regex = $decimal ? '[' . $decimal . ']' . '[0-9]' . $dec_prec : ''; if (!ereg("^[-\+0-9]+($dec_regex)?\$", $number)) { return false; } if ($decimal != '.') { $number = preg_replace("/[$decimal]/", '.', $number); } $number = (float)$number; if ($min !== null && $min > $number) { return false; } if ($max !== null && $max < $number) { return false; } return true; } If no prob, I/you commit ? pa

« previous php.pear.cvs (#4237) next »