PHP: Best way to check if input is a valid number? PHP: Best way to check if input is a valid number? php php

PHP: Best way to check if input is a valid number?


I use

if(is_numeric($value) && $value > 0 && $value == round($value, 0)){

to validate if a value is numeric, positive and integral

http://php.net/is_numeric

I don't really like ctype_digit as its not as readable as "is_numeric" and actually has less flaws when you really want to validate that a value is numeric.


filter_var()

$options = array(    'options' => array('min_range' => 0));if (filter_var($int, FILTER_VALIDATE_INT, $options) !== FALSE) { // you're good}