Revision: 65844
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at January 28, 2014 22:49 by apphp-snippets
Initial Code
<?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!'; } ?>
Initial URL
http://www.apphp.com/index.php?snippet=php-validate-ip-address
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
PHP