Possible Duplicate:
What's the correct way to test if a variable is a number in PHP?
I have two variables coming in from a form:
$minNo = mysql_real_escape_string($_GET["minNo"]);
$maxNo = mysql_real_escape_string($_GET["maxNo"]);
How can I check whether they are numerical values or not?
php $var_name=127.55; if (is_double($var_name)) echo 'This is a double value. <br>'; else echo 'This is not a double value.
The is_numeric() function checks whether a variable is a number or a numeric string. This function returns true (1) if the variable is a number or a numeric string, otherwise it returns false/nothing.
PHP – How to check if String contains Number(s)? ctype_digit() function returns true if the string passed to it has digits for all of its characters, else it returns false.
PHP supports the following data types: String. Integer. Float (floating point numbers - also called double)
Try is_numeric.
Finds whether the given variable is numeric. Numeric strings consist of optional sign, any number of digits, optional decimal part and optional exponential part. Thus +0123.45e6 is a valid numeric value. Hexadecimal notation (0xFF) is allowed too but only without sign, decimal and exponential part.
Use is_numeric
function, it returns bool value:
is_numeric($element)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With