Justtechjobs.com Find a programming school near you






Online Campus Both


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.
| Does anybody know if such validation can be done server side or
| definitely must be done client side?

Brad S Jackson replied suggesting that the php function preg_match()
should be used for this type of server side validation.

^^^^^^^^^^^^^^^^^^^^^^
Brad,

----- Original Message -----
From: Brad S. Jackson <bjackson <email protected>>
To: boclair <boclair <email protected>>
Sent: Thursday, April 05, 2001 11:54 PM
Subject: Re: [PHP-DB] Forms : Validating user input is integer

>
>
> This is probably the most efficient way to check. The preg
functions are faster
> than the ereg functions so I never use ereg. I think server side
validation is
> required and client side is optional.
>
> if(preg_match("/^[0-9]+$/", $var))
> echo "Valid";
> else
> echo "Invalid";

There you go. Does the same job as Matt William's eregi()

I am getting invaluable lessons on this stuff, which I never
understood before.

Using the php preg_match() function the tested script is
_________________________
<?
if ((@!$submit) || empty($num) )
 {
       echo "<div align='center'><span class='note'>No entry was
made</span></div>";
    include "get_id.php";
 }
if(preg_match("/^[0-9]+$/", $num))
 {
       include "do_form.php";
   }
else
   {
       echo "<div align='center'><span class='note'>The ID should have
been a number.</span></div>";
    include "get_id.php";
 }
?>
_______________________

Many thanks
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Tim Morris

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