Possible duplicate:Regular expression that matches valid IPv6 addresses
Can anyone know the regex
for checking ip-addresses in ipv6 format
Try:
$ipv6="2a01:e35:aaa4:6860:a5e7:5ba9:965e:cc93"; var_dump(filter_var($ipv6,FILTER_VALIDATE_IP, FILTER_FLAG_IPV6));
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 }
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);