php

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");
    }
?>
Was this helpful?