🔍Regex Recipes

IPv6 Address (Basic)

Basic IPv6 address validation with common format support and important caveats.

Pattern

^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::([0-9a-fA-F]{1,4}:){0,6}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:)$

Explanation

Basic IPv6 validation covering common formats. Full IPv6 validation is complex; consider using libraries.

Examples

Full format
Input
2001:0db8:85a3:0000:0000:8a2e:0370:7334
Output
✓ Match
Compressed
Input
2001:db8:85a3::8a2e:370:7334
Output
✓ Match
Loopback
Input
::1
Output
✓ Match
IPv4-mapped
Input
::ffff:192.168.1.1
Output
✗ No match (not covered)

Code Examples

JavaScript
// For production, use a library
function isValidIPv6(ip) {
  try {
    const url = new URL(`http://[${ip}]`);
    return true;
  } catch {
    return false;
  }
}

Try it Now

💡 Tips

  • Use ipaddress library (Python) or similar
  • IPv6 has many valid formats due to compression
  • Consider zone identifiers (%interface)
  • Test with real IPv6 addresses from your use case

⚠️ Common Pitfalls

  • IPv6 validation is extremely complex
  • Does not handle all compression formats
  • Does not validate IPv4-mapped IPv6 addresses
  • Strongly recommend using IP address libraries