3

Possible Duplicate:
Regular expression that matches valid IPv6 addresses

Can any one know the regular expression

for validating an ip address ,in ipv6 format

Community
  • 1
  • 1
user310849
  • 75
  • 1
  • 2
  • 6

3 Answers3

3

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
}
John Cartwright
  • 5,109
  • 22
  • 25
3

Try:

$ipv6="2a01:e35:aaa4:6860:a5e7:5ba9:965e:cc93";
var_dump(filter_var($ipv6,FILTER_VALIDATE_IP, FILTER_FLAG_IPV6));
Pwnna
  • 9,178
  • 21
  • 65
  • 91
0

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);
fvox
  • 1,077
  • 6
  • 8