* @return bool
*/
static function isIP( $name ) {
- return preg_match('/^\d{1,3}\.\d{1,3}\.\d{1,3}\.(?:xxx|\d{1,3})$/',$name);
+ return preg_match('/^\d{1,3}\.\d{1,3}\.\d{1,3}\.(?:xxx|\d{1,3})$/',$name) || User::isIPv6($name);
/*return preg_match("/^
(?:[01]?\d{1,2}|2(:?[0-4]\d|5[0-5]))\.
(?:[01]?\d{1,2}|2(:?[0-4]\d|5[0-5]))\.
$/x", $name);*/
}
+ /**
+ * Check if $name is an IPv6 IP.
+ */
+ static function isIPv6($name) {
+ /*
+ * if it has any non-valid characters, it can't be a valid IPv6
+ * address.
+ */
+ if (preg_match("/[^:a-fA-F0-9]/", $name))
+ return false;
+
+ $parts = explode(":", $name);
+ if (count($parts) < 3)
+ return false;
+ foreach ($parts as $part) {
+ if (!preg_match("/^[0-9a-fA-F]{0,4}$/", $part))
+ return false;
+ }
+ return true;
+ }
+
/**
* Is the input a valid username?
*