Regular expression for checking ip address in ipv6 format

Possible duplicate:
Regular expression that matches valid IPv6 addresses

Can anyone know the regex

for checking ip-addresses in ipv6 format

+3
source share
3 answers

Try:

$ipv6="2a01:e35:aaa4:6860:a5e7:5ba9:965e:cc93";
var_dump(filter_var($ipv6,FILTER_VALIDATE_IP, FILTER_FLAG_IPV6));
+3
source

If regex is not a strict requirement (I do not recommend it here), then:

if(filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
  // valid
}
else {
  // invalid
}
+3
source

You can try using Net_IPv6 , with the checkIPv6 () function .

If you want to accept IPv4 and IPv6, try using the filter_var () function :

$valid = filter_var($ip, FILTER_VALIDATE_IP);
0
source

All Articles