Skip to content

Instantly share code, notes, and snippets.

@apphp
Created January 26, 2014 11:28
Show Gist options
  • Save apphp/8631352 to your computer and use it in GitHub Desktop.
Save apphp/8631352 to your computer and use it in GitHub Desktop.
Validate IP address in PHP
<?php
$ip_address = '127.0.0.1';
if(preg_match('/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/', $ip_address)){
echo 'IP address is valid!';
}else{
echo 'IP address is NOT valid!';
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment