Search code snippets, questions, articles...

Validate a number using filter_var() method in PHP

If you want to validate a number in PHP you can use the filter_var() method and pass value and FILTER_VALIDATE_INT as parameters.
    $value = 500;

    if (!filter_var($value, FILTER_VALIDATE_INT) === false) {
        echo("Value is valid");
    } else {
        echo("Value is invalid");

    // -> Value is valid
Was this helpful?
Programming Feeds
Learn something new everyday on Devsheet