开发者

Regular expression for validating an ip address ,in ipv6 format [duplicate]

开发者 https://www.devze.com 2023-03-11 23:53 出处:网络
This question already has answers here: Closed 11 years ago. Possible Duplicate: Regular expression that match开发者_开发知识库es valid IPv6 addresses
This question already has answers here: Closed 11 years ago.

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);
0

精彩评论

暂无评论...
验证码 换一张
取 消