Posted By

apphp-snippets on 01/28/14


php validation apphp

Versions (?)

Validate IP Address in PHP

 / Published in: PHP


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.

  1. <?php
  2. $ip_address = '';
  4. if(preg_match('/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/', $ip_address)){
  5. echo 'IP address is valid!';
  6. }else{
  7. echo 'IP address is NOT valid!';
  8. }
  9. ?>

Report this snippet  

You need to login to post a comment.