Forum Moderators: coopster
if ($a + 0!= 0) // it's an number
...adding 0 to $a will attempt to convert $a to a number, and if it can't be converted, $a+0 wil equal 0. In this case, $a might also contain some letter charachters, too, however--or $a might be equal to zero, which IS a number...
For more precision, you might also do something like:
if (preg_match('/^(\d+)$/',$a)) // it's an integer If you want to allow for floats, you'd have to allow for a single decimal in the regex, too.
I hope this helps.
if (isset($_POST['variable'])However, be careful with is_int()! Anything over 10 digits is no longer an integer, it's a float! That's when I have found it best to use a regular expression.
&& is_numeric($_POST['variable'])
&& is_int($_POST['variable'] + 0)
)
if (isset($_POST['variable'])
&& is_numeric($_POST['variable'])
&&!preg_match('/[[:^digit:]]/', $_POST['variable'])
)