johnmahugu

php - check IP address validity

Jun 14th, 2015
332
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.34 KB | None | 0 0
  1. /*
  2. Is IPAdress valid
  3.  
  4. Checks if a IP adress has a valid format
  5. */
  6. // Sorry, currently I did not make a routine for IPv6,
  7. // but I'm sure you find one at: http://regexlib.com/
  8.  
  9. function IsIPValid($ip){
  10.  
  11.     if (preg_match('/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/', $ip)){
  12.         return true;
  13.     }
  14.  
  15.     return false;
  16. }
Advertisement
Add Comment
Please, Sign In to add comment