What is the best way of checking if input is numeric?
Those kind of numbers should not be valid. Only numbers like: 123, 012 (12), positive numbers should be valid. This is mye current code:
$num = (int) $val;
if (
preg_match('/^\d+$/', $num)
&&
strval(intval($num)) == strval($num)
)
{
return true;
}
else
{
return false;
}
ctype_digit
was built precisely for this purpose.