REGEXVAULTv2.0
Web & Network/IPv6
Verified Safe

IPv6 Link-Local Address Regex for PHP

/^[Ff][Ee][89AaBb][0-9a-fA-F](?::[0-9a-fA-F]{0,4}){0,7}(?:%[a-zA-Z0-9_.-]{1,20})?$/

What this pattern does

This page provides a comprehensive, battle-tested regular expression for matching ipv6 link-local address, ported and verified for PHP. A rigorously tested regex reduces debugging time and protects your application from edge-case failures. The snippet below is ready to drop into your PHP project — whether you're validating in a Laravel validator, a WordPress plugin, or a standalone PHP script.

Php Implementation

Php
<?php
// IPv6 Link-Local Address
// ReDoS-safe | RegexVault — Web & Network > IPv6

define('IPV6_LINKLOCAL_ADDRESS_PATTERN', '/^[Ff][Ee][89AaBb][0-9a-fA-F](?::[0-9a-fA-F]{0,4}){0,7}(?:%[a-zA-Z0-9_.-]{1,20})?$/');

function validate_ipv6_linklocal_address(string $input): bool {
    return (bool) preg_match(IPV6_LINKLOCAL_ADDRESS_PATTERN, $input);
}

// Example
var_dump(validate_ipv6_linklocal_address("fe80::1")); // bool(true)

Test Cases

Matches (Valid)
Rejects (Invalid)
fe80::1fc00::1
fe80::1%eth02001:db8::1
fe80::a1b2:c3d4:e5f6:0001::1
fe80::1%lo0fe80::1%
FE80::1%en0fe70::1

When to use this pattern

This pattern is drawn from the Web & Network > IPv6 category and carries a ReDoS-safe certification. That matters for PHP developers because especially relevant in PHP where PCRE backtracking limits can trigger silent failures on malicious input. RegexVault audits patterns against known backtracking attack vectors, ensuring you have the necessary context before using this regex in a high-stakes production environment.

Common Pitfalls

Zone IDs (the %eth0 part) are OS-specific and not part of the RFC 4007 standard address format — strip them before storage or comparison.

Technical Notes

The fe80::/10 block means the first 10 bits are 1111111010, which covers fe80 through febf. The [89AaBb] in position 3 covers the valid second-nibble range for this prefix.

Have a pattern that belongs in the vault?

Submit it for review — community-verified patterns get credited to your GitHub handle. Free submissions join the queue. Priority review available for $15.

Submit a Pattern