Re: Re: Simple validation problem

From: Date: Thu, 19 Jul 2001 15:22:07 +0000
Subject: Re: Re: Simple validation problem
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-58720@lists.php.net to get a copy of this message
Ok forget it, someone suggest to me: if ((string)((float)$amount) == $amount && (float)$amount > 0) { print "ok"; }else print "error"; and it works perfectly! py ----- Original Message ----- From: py <pylem@sympatico.ca> To: <php-general@lists.php.net> Sent: Thursday, July 19, 2001 11:14 AM Subject: Re: [PHP] Re: Simple validation problem > I wonder how that can be enough, if you consider the following form, > you can enter "45-98" and it will print ok !! > > Since all http is coming as a string, I beleive the only way is to test for > invalid > characters as anything except [0-9] and the dot. (wich is my problem > because I do not really know how) > I event try with casting amount like this: > $amount = (float)($amount); > It does not work, I can still input "12r5" for exemple. > > py > > if( $amount >0 ){ > print "ok"; > }else print "smaller than 0: error"; > > if( is_float( $amount )){ > print "ok"; > }else print "not a float: error"; > ?> > <FORM ACTION="<? print $PHP_SELF ?>" METHOD="post"> > <INPUT TYPE="Text" NAME="amount" SIZE="4"> > <INPUT TYPE="Submit" NAME="Submit" VALUE="Submit"> > </FORM> > > ----- Original Message ----- > From: CC Zona <cczona@nospam.invalid> > To: <php-general@lists.php.net> > Sent: Wednesday, July 18, 2001 10:15 PM > Subject: [PHP] Re: Simple validation problem > > > > In article <00ef01c10fa5$fd20f2e0$e064fea9@py>, pylem@sympatico.ca (Py) > > wrote: > > > > > I am trying to make shure the amount is positive > > > > if($amount >0) > > {...} > > > > > and is a float > > > > if(is_float($amount)) > > {...} > > > > -- > > CC > > > > -- > > PHP General Mailing List (http://www.php.net/) > > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > > For additional commands, e-mail: php-general-help@lists.php.net > > To contact the list administrators, e-mail: php-list-admin@lists.php.net > > > > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net >

« previous php.general (#58720) next »