Search code snippets, questions, articles...

Validate IP address using filter_var() method PHP

You can use filter_var() with FILTER_VALIDATE_IP to validate an IP address in PHP. Below is the code example for that.
<?php
    $ip_address = "168.0.0.1";

    if (filter_var($ip_address, FILTER_VALIDATE_IP) == true) {
        echo("Valid IP");
    } else {
        echo("Invalid Ip");
    }
?>
Best JSON Validator, JSON Tree Viewer, JSON Beautifier at same place.
Was this helpful?
0 Comments