you do the isset() before calling the function
PHP Code:is_whole_number($var)
I'm using this function from PHP: is_numeric - Manual
Now this works to see if the input is a numeral. But what should I do to check if the value is set in the first place ? I tried PHP: isset - Manual isset but that didn't swing it.PHP Code:function is_whole_number($var){
return (is_numeric($var)&&(intval($var)==floatval($var)));
}
I'm sure it's something obvious I am missing. Any hints ? Thanks ?
my sites :
you do the isset() before calling the function
PHP Code:is_whole_number($var)
:. Web Design & Development Web Design Ireland
:. Search Engines Optimization Search Engines Optimization
:. Car Parts & Accessories Car Parts
:. Cars Ireland Cars Ireland
:. I Have 2 Find It Directory SEF Directory
Thanks Louie for the help
Still having problems though
still bails out when I don't have a value in my form to check.PHP Code:function is_whole_number($var){
return (is_numeric($var) && (intval($var)==floatval($var)) && ($var!=NULL) );
}
if ( isset($_POST[checkit]) && is_whole_number($_POST[checkit])){
// do
}else {
// no do
}
I have an input box that I want people to either leave blank, or enter a numeral. Otherwise if they enter 'six' or something like that I want it to report the error.![]()
Last edited by paul; 22-02-2007 at 09:18 PM. Reason: more info
my sites :
don't get it. what format are you loonking to get from the visitor?
like 6.00 or 6
give an example
:. Web Design & Development Web Design Ireland
:. Search Engines Optimization Search Engines Optimization
:. Car Parts & Accessories Car Parts
:. Cars Ireland Cars Ireland
:. I Have 2 Find It Directory SEF Directory
Hi Louie,
I want to make sure that a user gives a whole decimal. The field is four characters long, and I am afraid some bright spark will enter 'five' instead of '5'. So only a whole number will do. No "two" "2,3" or "2.3" values should be accepted only 2.
my sites :
try this:
PHP Code:
if (isset($_POST['checkit'])){
$no_post = trim($_POST['checkit']);
if(is_numeric($no_post)){
// do something here cause is number
}else {
// no do only numbers
}
}else{
//you haven't enter any numbers
}
:. Web Design & Development Web Design Ireland
:. Search Engines Optimization Search Engines Optimization
:. Car Parts & Accessories Car Parts
:. Cars Ireland Cars Ireland
:. I Have 2 Find It Directory SEF Directory
Thanks mate.Will check this out tomorrow. Time to call it a day here
my sites :
sorry about this I forgot to mention that if he enters a null value then that is okay.
so logic
Code:is NULL == okay proceed is ! NULL IS NUMERIC == okay proceed IS NOT NUMERIC == give out error.
my sites :
PHP Code:if (isset($_POST['checkit'])){
$no_post = trim($_POST['checkit']);
if(is_numeric($no_post)){
// do something here cause is number
}else {
// no do only numbers
}
}
:. Web Design & Development Web Design Ireland
:. Search Engines Optimization Search Engines Optimization
:. Car Parts & Accessories Car Parts
:. Cars Ireland Cars Ireland
:. I Have 2 Find It Directory SEF Directory
Cheers for your help louie and pointing me in the right direction.
The problem was checking if something was NULL . I used
PHP Code:function is_whole_number($var){
return (is_numeric($var)&&(intval($var)==floatval($var)));
}
function postvars() {
foreach(func_get_args() as $var) {
// echo $var. " ". $_POST[$var]." <br/>" ;
if( $_POST[$var] === '' || is_whole_number($_POST[$var])) return true;
}
return false;
}
$happy = (postvars('checkit'));
my sites :