Validate Value as Integer in PHP

Simple PHP function that checks if the variable $int is a valid integer number. The function below returns true also if the $int variable is 0:

function is_valid_integer($int)
{
    return (filter_var($int, FILTER_VALIDATE_INT) === 0 || filter_var($int, FILTER_VALIDATE_INT) !== FALSE) ? true : false;
}

More information:

http://php.net/manual/en/filter.filters.validate.php

More Related Posts