Verify IPv4 address in php using regex
Posted by Marius Voila on August 26, 2010 in London, U.K . — 0 comments This post contains 72 wordsA simple function in php to verify IPV4 Address. It is completely based in regex and does full ip verifying. It tests the ip for;
- Need 4 numeric blocks separated by a dot.
- Each numeric block must noot exceed 255.
-
Shouldn’t contain space. So remember to trim before calling this function.
function isINetAddress($ipaddr){ if( preg_match( “/^((?:25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9]).){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])$/m”,$ipaddr) > 0) return true; }
This can’t me more simpler. ;) Enjoy!