Possible Duplicate:
Regular expression that match开发者_开发知识库es valid IPv6 addresses
Can any one know the regular expression
for validating an ip address ,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 solid requirement (I don't recommend it here), then:
if(filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
// valid
}
else {
// invalid
}
You can try to use Net_IPv6, with the function checkIPv6().
If you want to accept IPv4 and IPv6, try to use the function filter_var():
$valid = filter_var($ip, FILTER_VALIDATE_IP);
精彩评论