RE: [PHP] Validating user input

From: Date: Tue, 03 Jun 2003 10:55:12 +0000
Subject: RE: [PHP] Validating user input
Groups: php.general 
Request: Send a blank email to php-general+get-149928@lists.php.net to get a copy of this message
> -----Original Message----- > From: Shaun [mailto:shaun@mania.plus.com] > Sent: 03 June 2003 10:21 > > I am creating a timesheet application, how can I make sure > that a user has > entered a number, and that the number is a whole number or a > decimal up to 2 > places, and that the number is less than 24? I'd probably do this with a regex plus a quick test for in-range values -- something like (untested): if ($number>0 && $number<24 && preg_match('^[0-9]{1-2}(\.[0-9]{1,2})?$', $number)) do_stuff; You could also tweak the regex to filter out out-of-range values and dispense with the range checks -- something like (again untested): if (preg_match('^(1?[0-9]|2[0-4])(\.[0-9]{1,2})?$', $number)) do_stuff; Cheers! Mike --------------------------------------------------------------------- Mike Ford, Electronic Information Services Adviser, Learning Support Services, Learning & Information Services, JG125, James Graham Building, Leeds Metropolitan University, Beckett Park, LEEDS, LS6 3QS, United Kingdom Email: m.ford@lmu.ac.uk Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211

« previous php.general (#149928) next »