luci-base: add hostport and ipaddrport validation types
[project/luci.git] / modules / luci-base / luasrc / cbi / datatypes.lua
index c52ac46..52f90af 100644 (file)
@@ -1,4 +1,4 @@
--- Copyright 2010 Jo-Philipp Wich <xm@subsignal.org>
+-- Copyright 2010 Jo-Philipp Wich <jow@openwrt.org>
 -- Licensed to the public under the Apache License 2.0.
 
 local fs = require "nixio.fs"
@@ -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)