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.
<?php
    $value = 500;

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

    // -> Value is valid
?>
Best JSON Validator, JSON Tree Viewer, JSON Beautifier at same place.
Was this helpful?
0 Comments