> -----Original Message-----
> From: Shaun [mailto:[EMAIL PROTECTED]
> 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: [EMAIL PROTECTED]
Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php