> <?
> 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.



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to