[TYPO3-core] RFC: Bug 331: Support IPv6 addresses
Franz Holzinger
franz at fholzinger.com
Tue Mar 7 17:26:02 CET 2006
Hello Michael,
>
>
>>>+ function validIPv6($ip) {
>>>+ $uppercaseIP = strtoupper($ip);
>>>+
>>>+ $regex = "/^(";
>>>+ $regex.= "(([\dA-F]{1,4}:){7}[\dA-F]{1,4})|";
>>>+ $regex.= "(([\dA-F]{1,4}){1}::([\dA-F]{1,4}:){1,5}[\dA-F]{1,4})|";
>>>+ $regex.= "(([\dA-F]{1,4}:){2}:([\dA-F]{1,4}:){1,4}[\dA-F]{1,4})|";
>>>+ $regex.= "(([\dA-F]{1,4}:){3}:([\dA-F]{1,4}:){1,3}[\dA-F]{1,4})|";
>>>+ $regex.= "(([\dA-F]{1,4}:){4}:([\dA-F]{1,4}:){1,2}[\dA-F]{1,4})|";
>>>+ $regex.= "(([\dA-F]{1,4}:){5}:([\dA-F]{1,4}:){0,1}[\dA-F]{1,4})|";
>>>+ $regex.= "(::([\dA-F]{1,4}:){0,6}[\dA-F]{1,4})";
>>>+ $regex.= ")$/";
>>>
>>>
>>>
>>>
>>I think it should be possible to find a more simple regular expression
>>for that.
>>
>>
>
>How? Please make a suggestion if you know how to optimize this.
>
>
>
What about this?
function validIPv6($ip) {
$bValid = true;
$ipTest = $ip;
// check for more than one '::'
$ddpos = strpos ($ipTest, '::');
if (!$ddpos===FALSE) {
$tmpIp = substr ($ipTest, $ddpos);
$tmppos = strpos ($tmpIp, '::');
if ($tmppos === FALSE) {
// remove '::'
$ipTest = substr ($ipTest, 0, $ddpos);
$ipTest .= substr ($ipTest, $ddpos + 2);
} else {
$bValid = false;
}
}
// check colon at the end
if (substr($ipTest,-1,1) == ':')
$bValid = false;
// dummy colon at the end
$ipTest .= ':';
if ($bValid) {
$regex = "/^(";
$regex.= "(([\dA-F]{1,4}:){1,8})";
$regex.= ")$/i";
if (!preg_match($regex, $ipTest))
$bValid = false;
}
return $bValid;
However I could not test it. So tell me what's wrong or how to test.
Greets,
Franz
More information about the TYPO3-team-core
mailing list