Link to home
Start Free TrialLog in
Avatar of Solutionabc
Solutionabc

asked on

PHP FILTER_VALIDATE_INT

hi,

How would I validate a users integer input with this function?
I want the min number to be 0 and max to be 9.

and what if I have multiple user values that I want to validate do I put it in an array?


thanks!
Avatar of Rajesh Dalmia
Rajesh Dalmia
Flag of India image

can try something like....

<?php

$intVal = $_REQUEST['FormField'];

if($intVal > 0 and $intVal < 9)
{
echo "valid no.";
}
else
{
echo "invalid";
}

?>
Avatar of Solutionabc
Solutionabc

ASKER

If I have the code below, and verseQ = 10, will var_dump return false?

if it does how do I check the returned value?
$verseQ = $_POST["verseQb"];

$int_verseQ = array("options"=>
array("min_range"=>0, "max_range"=>9));

var_dump(filter_var($verseQ, FILTER_VALIDATE_INT, $int_verseQ));

Open in new window

yes...
but if code not working then have to check what values is getting assigned to verseQ.

to make sure it always have integer value change the line to

$verseQ = $_POST["verseQb"] + 0;
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial