Skip to content
Snippets Groups Projects
Commit 47aa28c6 authored by Jared Hancock's avatar Jared Hancock
Browse files

Support validation of IPv4 and IPv6 addresses

parent 2f4a7efd
No related branches found
No related tags found
No related merge requests found
......@@ -172,10 +172,15 @@ class Validator {
return false;
$ip=trim($ip);
if(preg_match("/^[0-9]{1,3}(.[0-9]{1,3}){3}$/",$ip)) {
foreach(explode(".", $ip) as $block)
if($block<0 || $block>255 )
return false;
# Thanks to http://stackoverflow.com/a/1934546
if (function_exists('inet_pton')) { # PHP 5.1.0
# Let the built-in library parse the IP address
return @inet_pton($ip) !== false;
} else if (preg_match(
'/^(?>(?>([a-f0-9]{1,4})(?>:(?1)){7}|(?!(?:.*[a-f0-9](?>:|$)){7,})'
.'((?1)(?>:(?1)){0,5})?::(?2)?)|(?>(?>(?1)(?>:(?1)){5}:|(?!(?:.*[a-f0-9]:){5,})'
.'(?3)?::(?>((?1)(?>:(?1)){0,3}):)?)?(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])'
.'(?>\.(?4)){3}))$/iD', $ip)) {
return true;
}
return false;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment