RE: [PHP] checking to see if value is a integer from a form text field

From: Date: Fri, 16 Feb 2001 01:43:17 +0000
Subject: RE: [PHP] checking to see if value is a integer from a form text field
Groups: php.general 
Request: Send a blank email to php-general+get-40016@lists.php.net to get a copy of this message
> I have a strange problem, when a user inputs the quantity > into a text input field in a cart, I want to be able to test > to see if the value is a integer if it isn't then default it to 1 > > if ( !is_int($Qty) ) { > $Qty = 1; > } Off the top of my head (and thus probably hideously wrong), how about: $ActualQty = ereg_replace("[^0-9]", "", $Qty); if (intval($ActualQty) <= 0) { $Qty = 1; } Here we're removing everything that's NOT between 0 and 9, and then checking to see if the variable has a value. Jason

« previous php.general (#40016) next »