php-db | 2001041

Re: [PHP-DB] Forms : Validating user input is integer From: Boclair (boclair <email protected>)
Date: 04/05/01

"boclair" <boclair <email protected>> wrote in message
news:002101c0bd8e$30742e60$7ac22dcb <email protected>
| I have a problem with a user input in a form required to be an
| integer, creating a variable for a mysql query.
|
| I have instances where integer, 0, is being typed as letter,o.
|
| The last discussion of validating the input was
| http://marc.theaimsgroup.com/?l=php-db&m=97207172003983&w=2
|
| There it was suggested that the only way to validate the input was
| using javascript. I have a case where clients have disabled
| javascript.

For those who may be interested here is the server side method using
eregi() as explained by Matt Williams

xxxxxxxxxxxxxxxxxxxxxxxxxx

----- Original Message -----
From: Matt Williams <matt <email protected>>
To: boclair <boclair <email protected>>
Sent: Thursday, April 05, 2001 8:05 PM
Subject: RE: [PHP-DB] Forms : Validating user input is integer

> try elseif(!eregi("[0-9]",$num))

To gain the full benefit of your suggestion I find that I can validate
for a wrong entry containing a mix alphabetical and numerical
characters by altering the elseif line to read

elseif (!eregi("[0-9]",$num) || eregi("[a-z]",$num))

This gives the full script as

_____________________________

<?
if ((@!$submit) || empty($num) )
 {
       echo "<div align='center'><span class='note'>No entry was
made</span></div>";
    include "get_id.php";
 }
elseif(!eregi("[0-9]",$num) || eregi("[a-z]",$num))
   {
       echo "<div align='center'><span class='note'>Entry error. The
ID should have been a number.</span></div>";
    include "get_id.php";
 }
else
 {
       include "do_form.php";
   }
?>
_____________________

Agreed?

Tim
xxxxxxxxxxxxxxxxxxxx

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: php-db-unsubscribe <email protected>
For additional commands, e-mail: php-db-help <email protected>
To contact the list administrators, e-mail: php-list-admin <email protected>