Return to Snippet

Revision: 65844
at January 28, 2014 22:49 by apphp-snippets

Initial Code
$ip_address = '';
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!';
   echo 'IP address is NOT valid!';

Initial URL

Initial Description
This code demonstrates a simple way to validate IP address using preg_match() PHP function. This is a very simple code, that allows you to perform this task quickly with a minimum lines of code.

Initial Title
Validate IP Address in PHP

Initial Tags
php, validation

Initial Language