I have a form, and I need to check out if some values are integer. This seems unexepctedly complicated.
I tried:
if (is_int($value))
this doen’t work: any value return false, because the text input always sends a string type variable
if (is_numeric($value))
this works, but only check if variable is numeric. I want to know if it is an integer, so I don’t want that 1.3 is accepted.
if (is_int( (int) $value ))
Tried to use is_int, and force cast $value as integer. This doesn’t work either
So, unless there is some other solution which I’m not aware of, I guess the only way is to use
ereg("^[0-9]*$",$value)
Is there any problem with this (performance?), and aren’t there really more straightforward solutions?
Kind regards.
As noted by mario,
ctype_digit()is the single, function way to go:Simple. Fast. Reliable.