modules/luci-base: Fix ipaddrport validator to support ipv6
[project/luci.git] / modules / luci-base / htdocs / luci-static / resources / cbi.js
index 4b7227f..19a1ede 100644 (file)
@@ -172,17 +172,38 @@ var cbi_validators = {
                return false;
        },
 
-       'ipaddrport': function()
+       'ip4addrport': function()
        {
                var hp = this.split(/:/);
 
                if (hp.length == 2)
                        return (cbi_validators.ipaddr.apply(hp[0]) &&
                                cbi_validators.port.apply(hp[1]));
-
                return false;
        },
 
+       'ipaddrport': function(bracket)
+       {
+               if (this.match(/^([^\[\]:]+):([^:]+)$/)) {
+                       var addr = RegExp.$1
+                       var port = RegExp.$2
+                       return (cbi_validators.ip4addr.apply(addr) &&
+                               cbi_validators.port.apply(port));
+                } else if ((bracket == 1) && (this.match(/^\[(.+)\]:([^:]+)$/))) {
+                       var addr = RegExp.$1
+                       var port = RegExp.$2
+                       return (cbi_validators.ip6addr.apply(addr) &&
+                               cbi_validators.port.apply(port));
+                } else if ((bracket != 1) && (this.match(/^([^\[\]]+):([^:]+)$/))) {
+                       var addr = RegExp.$1
+                       var port = RegExp.$2
+                       return (cbi_validators.ip6addr.apply(addr) &&
+                               cbi_validators.port.apply(port));
+               } else {
+                       return false;
+               }
+       },
+
        'wpakey': function()
        {
                var v = this;