Re: Forms : Validating user input is integer
| From: | boclair | Date: | Fri, 06 Apr 2001 00:41:40 +0000 |
| Subject: | Re: Forms : Validating user input is integer | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-8287@lists.php.net to get a copy of this message | ||
----- Original Message -----
From: Matt Williams <matt@yewlands.com>
To: Boclair <boclair@bigpond.net.au>; <php-db@lists.php.net>
Sent: Thursday, April 05, 2001 11:28 PM
Subject: RE: [PHP-DB] Forms : Validating user input is integer
The line should read, and as I tested it,
> >
> > elseif (eregi("[a-zA-Z]",$num)) { }
> >
> > Do you see any problem with this?
>
> Yes, same thing it will accept other character like !*- etc...
>
> try
>
> if(!eregi("^[0-9]+[0-9]*$",$num)
>
> file://error
> }
You are right again. Stops all further processing of the inserted
variable if it is not entirely composed of digits.
It did not cross my mind to check for ! (shift 1) and similar entry
errors.
Once again, thanks.
Tim
So here is the final working script
<?
if ((@!$submit) || empty($num) )
{
echo "<div align='center'><span class='note'>No entry was
made</span></div>";
include "get_id.php";
}
if(!eregi("^[0-9]+[0-9]*$",$num))
{
echo "<div align='center'><span class='note'>The ID
should have
been a number.</span></div>";
include "get_id.php";
}
else
{
include "do_form.php";
}
?>
Tim