IPV6 REGXP

IPV4 & IPV6 validation logic

HTML

Enter IP Address =
<input type='text' name='ipv6' id='ipv6ID' onblur="ipv6test()"/>
<div id="status"></div>

JavaScript

$(function () {
    $("#ipv6ID").blur(function () {
        ipv6test(1, $(this).val());

        ipv6test(!1, ""); // empty string 
        ipv6test(1, "::1"); // loopback, compressed, non-routable 
        ipv6test(1, "::"); // unspecified, compressed, non-routable 
        ipv6test(1, "0:0:0:0:0:0:0:1"); // loopback, full 
        ipv6test(1, "0:0:0:0:0:0:0:0"); // unspecified, full 
        ipv6test(1, "2001:DB8:0:0:8:800:200C:417A"); // unicast, full 
        ipv6test(1, "FF01:0:0:0:0:0:0:101"); // multicast, full 
        ipv6test(1, "2001:DB8::8:800:200C:417A"); // unicast, compressed 
        ipv6test(1, "FF01::101"); // multicast, compressed 
        ipv6test(!1, "2001:DB8:0:0:8:800:200C:417A:221"); // unicast, full 
        ipv6test(!1, "FF01::101::2"); // multicast, compressed 
        ipv6test(1, "fe80::217:f2ff:fe07:ed62");

        ipv6test(1, "2001:0000:1234:0000:0000:C1C0:ABCD:0876");
        ipv6test(1, "3ffe:0b00:0000:0000:0001:0000:0000:000a");
        ipv6test(1, "FF02:0000:0000:0000:0000:0000:0000:0001");
        ipv6test(1, "0000:0000:0000:0000:0000:0000:0000:0001");
        ipv6test(1, "0000:0000:0000:0000:0000:0000:0000:0000");
        ipv6test(!1, "02001:0000:1234:0000:0000:C1C0:ABCD:0876"); // extra 0 not allowed! 
        ipv6test(!1, "2001:0000:1234:0000:00001:C1C0:ABCD:0876"); // extra 0 not allowed! 
        //ipv6test(1," 2001:0000:1234:0000:0000:C1C0:ABCD:0876");		// leading space
        //ipv6test(1,"2001:0000:1234:0000:0000:C1C0:ABCD:0876");		// trailing space
        //ipv6test(1," 2001:0000:1234:0000:0000:C1C0:ABCD:0876  ");	// leading and trailing space
        ipv6test(!1, "2001:0000:1234:0000:0000:C1C0:ABCD:0876  0"); // junk after valid address
        ipv6test(!1, "2001:0000:1234: 0000:0000:C1C0:ABCD:0876"); // internal space

        ipv6test(!1, "3ffe:0b00:0000:0001:0000:0000:000a"); // seven segments
        ipv6test(!1, "FF02:0000:0000:0000:0000:0000:0000:0000:0001"); // nine segments
        ipv6test(!1,...