A select field on my HTML form may yield 1 to 5 (integers). Using is_int
rejects it every time, because the $_POST['rating']
is viewed as a string.
After consulting the PHP Manual, it seems is_numeric() && !is_float()
is the proper way to validate for an integer in this case.
But I want to be certain, so please confirm or fire away at my logic.
I would probably use something like this:
$value = filter_var(
$_POST['rating'],
FILTER_VALIDATE_INT,
array('options' => array('min_range' => 1, 'max_range' => 5)));
filter_var()
will return either boolean false
if the value is non-integer or out-of-range, or the valid value itself (as an integer.)
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