Re: how do I do this, please?

From: Date: Tue, 16 Jan 2001 03:40:18 +0000
Subject: Re: how do I do this, please?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-34751@lists.php.net to get a copy of this message
> <? > if (ereg !=("^[0-9]+[.]?[0-9]*$", $val1)) { > > header("Location:http://localhost/calculate_form.html"); > exit; > > But the script will attempt to perform calculations on non numeric > fields and > > I also want it to return the form if anyone puts in a non numeric value. > > I think I need some ereg something like: > > (ereg("^[0-9]+[.]?[0-9]*$", $i, $p)) I dunno what's in the book, but I think what is supposed to be there is somewhere between the two: if (!ereg("^[0-9]+[.]?[0-9]*$", $val1)) { header("Location:http://localhost/calculate_form.html"); exit; } In other words, if the first argument to your calculator doesn't look like a number, it sends you back. ^ means "must start with" [0-9] means "0 through 9" + means "at *least* one, but maybe more" [.] means "." ? means "maybe we'll have that '.', and maybe we won't" [0-9] means "0 through 9" * means "maybe none, or maybe lots" $ means "must end with" So, all together, it has to start with a digit, it might or might not have a decimal point, and it might or might not have a bunch more digits, and it has to end there without anything else.

« previous php.general (#34751) next »