IPv6 Link-Local Address Regex for JavaScript
/^[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 JavaScript. A rigorously tested regex reduces debugging time and protects your application from edge-case failures. The snippet below is ready to drop into your JavaScript project — whether you're validating in an Express middleware, a Next.js API route, or a client-side form.
Javascript Implementation
// IPv6 Link-Local Address
// ReDoS-safe | RegexVault — Web & Network > IPv6
const ipv6LinklocalAddressRegex = /^[Ff][Ee][89AaBb][0-9a-fA-F](?::[0-9a-fA-F]{0,4}){0,7}(?:%[a-zA-Z0-9_.-]{1,20})?$/;
function validateIpv6LinklocalAddress(input: string): boolean {
return ipv6LinklocalAddressRegex.test(input);
}
// Example
console.log(validateIpv6LinklocalAddress("fe80::1")); // trueTest Cases
Matches (Valid) | Rejects (Invalid) |
|---|---|
fe80::1 | fc00::1 |
fe80::1%eth0 | 2001:db8::1 |
fe80::a1b2:c3d4:e5f6:0001 | ::1 |
fe80::1%lo0 | fe80::1% |
FE80::1%en0 | fe70::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 JavaScript developers because especially critical in long-running Node.js event loops where a ReDoS vulnerability can block the entire process. 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