diff options
-rw-r--r-- | modules/luci-base/htdocs/luci-static/resources/cbi.js | 22 | ||||
-rw-r--r-- | modules/luci-base/luasrc/cbi/datatypes.lua | 10 |
2 files changed, 32 insertions, 0 deletions
diff --git a/modules/luci-base/htdocs/luci-static/resources/cbi.js b/modules/luci-base/htdocs/luci-static/resources/cbi.js index 02c54ad3e8..8a3cb6fca7 100644 --- a/modules/luci-base/htdocs/luci-static/resources/cbi.js +++ b/modules/luci-base/htdocs/luci-static/resources/cbi.js @@ -161,6 +161,28 @@ var cbi_validators = { cbi_validators.host.apply(this); }, + 'hostport': function() + { + var hp = this.split(/:/); + + if (hp.length == 2) + return (cbi_validators.host.apply(hp[0]) && + cbi_validators.port.apply(hp[1])); + + return false; + }, + + 'ipaddrport': function() + { + var hp = this.split(/:/); + + if (hp.length == 2) + return (cbi_validators.ipaddr.apply(hp[0]) && + cbi_validators.port.apply(hp[1])); + + return false; + }, + 'wpakey': function() { var v = this; diff --git a/modules/luci-base/luasrc/cbi/datatypes.lua b/modules/luci-base/luasrc/cbi/datatypes.lua index ebd7e594f7..52f90afee6 100644 --- a/modules/luci-base/luasrc/cbi/datatypes.lua +++ b/modules/luci-base/luasrc/cbi/datatypes.lua @@ -184,6 +184,16 @@ function network(val) return uciname(val) or host(val) end +function hostport(val) + local h, p = val:match("^([^:]+):([^:]+)$") + return not not (h and p and host(h) and port(p)) +end + +function ipaddrport(val) + local h, p = val:match("^([^:]+):([^:]+)$") + return not not (h and p and ipaddr(h) and port(p)) +end + function wpakey(val) if #val == 64 then return (val:match("^[a-fA-F0-9]+$") ~= nil) |