Re: shortest possible check: field is set, integer or 0

From: Date: Wed, 30 Nov 2005 23:19:37 +0000
Subject: Re: shortest possible check: field is set, integer or 0
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-226670@lists.php.net to get a copy of this message
On Wed, November 30, 2005 5:10 pm, Chris Lott wrote: > What is the shortest possible check to ensure that a field coming from > a form as a text type input is either a positive integer or 0, but > that also accepts/converts 1.0 or 5.00 as input? This might be good enough: if (isset($_POST['x'])){ if (!preg_match('/([0-9]*)(\\.0*)?/', $_POST['x']){ //invalid } else{ $_CLEAN['x'] = (int) $_POST['x']; } } -- Like Music? http://l-i-e.com/artists.htm

« previous php.general (#226670) next »