diff --git a/include/class.validator.php b/include/class.validator.php
index d41bf027fe826c855893146dfee680c578598feb..2cec3fa3f2f83d92e9a1a8e04a4174f78b3cc2ca 100644
--- a/include/class.validator.php
+++ b/include/class.validator.php
@@ -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;