From 294d996fc030ce368026ce2c40655196cd5bb93d Mon Sep 17 00:00:00 2001 From: Sumanth Dosapati Date: Sat, 11 Oct 2025 19:07:35 +0530 Subject: [PATCH 1/2] Create script.js --- .../Validate IPv6 Address/script.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 Specialized Areas/Regular Expressions/Validate IPv6 Address/script.js diff --git a/Specialized Areas/Regular Expressions/Validate IPv6 Address/script.js b/Specialized Areas/Regular Expressions/Validate IPv6 Address/script.js new file mode 100644 index 0000000000..0caf1f2cf6 --- /dev/null +++ b/Specialized Areas/Regular Expressions/Validate IPv6 Address/script.js @@ -0,0 +1,17 @@ +// IPv6 Address Validator +// This regex validates both full and compressed IPv6 address formats, including shorthand "::" notation. + +const ipv6Regex = + /^(?:(([0-9A-Fa-f]{1,4}:){7}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){1,7}:)|(([0-9A-Fa-f]{1,4}:){1,6}:[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){1,5}(:[0-9A-Fa-f]{1,4}){1,2})|(([0-9A-Fa-f]{1,4}:){1,4}(:[0-9A-Fa-f]{1,4}){1,3})|(([0-9A-Fa-f]{1,4}:){1,3}(:[0-9A-Fa-f]{1,4}){1,4})|(([0-9A-Fa-f]{1,4}:){1,2}(:[0-9A-Fa-f]{1,4}){1,5})|([0-9A-Fa-f]{1,4}:((:[0-9A-Fa-f]{1,4}){1,6}))|(:((:[0-9A-Fa-f]{1,4}){1,7}|:)))(%.+)?$/; + +function validateIPv6(address) { + return ipv6Regex.test(address); +} + +// Example usage: +console.log(validateIPv6("2001:0db8:85a3:0000:0000:8a2e:0370:7334")); // true (full) +console.log(validateIPv6("2001:db8:85a3::8a2e:370:7334")); // true (compressed) +console.log(validateIPv6("::1")); // true (loopback) +console.log(validateIPv6("fe80::")); // true (link-local) +console.log(validateIPv6("1234:5678:9abc:def0:1234:5678:9abc:defg")); // false (invalid hex) +console.log(validateIPv6("2001::85a3::7334")); // false (double compression) From 2f92dd60ad4fc42ff301ca94cfc64d621b634904 Mon Sep 17 00:00:00 2001 From: Sumanth Dosapati Date: Sat, 11 Oct 2025 19:08:43 +0530 Subject: [PATCH 2/2] Create README.md --- .../Regular Expressions/Validate IPv6 Address/README.md | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 Specialized Areas/Regular Expressions/Validate IPv6 Address/README.md diff --git a/Specialized Areas/Regular Expressions/Validate IPv6 Address/README.md b/Specialized Areas/Regular Expressions/Validate IPv6 Address/README.md new file mode 100644 index 0000000000..e4b6695fc5 --- /dev/null +++ b/Specialized Areas/Regular Expressions/Validate IPv6 Address/README.md @@ -0,0 +1,9 @@ +# IPv6 Address Validator + +This snippet validates **IPv6 addresses** in both full and compressed formats using JavaScript regex. + +### Features +- Supports full and shortened IPv6 formats (`::` compression) +- Validates loopback (`::1`) and link-local (`fe80::`) addresses +- Rejects invalid hex groups and multiple `::` +