Similar to r76267 but for JS. Should finish bug 24293.
authorAaron Schulz <aaron@users.mediawiki.org>
Sun, 7 Nov 2010 22:46:22 +0000 (22:46 +0000)
committerAaron Schulz <aaron@users.mediawiki.org>
Sun, 7 Nov 2010 22:46:22 +0000 (22:46 +0000)
skins/common/block.js

index 73ed71e..425733b 100644 (file)
@@ -29,7 +29,15 @@ window.updateBlockOptions = function() {
 
        var addy = target.value;
        var isEmpty = addy.match(/^\s*$/);
-       var isIp = addy.match(/^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}|:(:[0-9A-Fa-f]{1,4}){1,7}|[0-9A-Fa-f]{1,4}(:{1,2}[0-9A-Fa-f]{1,4}|::$){1,7})(\/\d+)?$/);
+
+       // @TODO: get some core JS IP functions
+       // Match the first IP in each list (ignore other garbage)
+       var isIpV4 = addy.match(/^(\d+\.\d+\.\d+\.\d+)(\/\d+)?$/);
+       // Regexp has 3 cases: (starts with '::',ends with '::',neither)
+       var isIpV6 = !addy.match(/::.*::/) // not ambiguous
+               && addy.match(/^(:(:[0-9A-Fa-f]{1,4}){1,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})(\/\d+)?$/);
+
+       var isIp = ( isIpV4 || isIpV6 );
        var isIpRange = isIp && addy.match(/\/\d+$/);
 
        var anonymousRow = document.getElementById( 'wpAnonOnlyRow' );