libs/web: add missing parts of previous commit
[project/luci.git] / libs / web / luasrc / cbi / datatypes.lua
index 6640db6..93b29cb 100644 (file)
@@ -141,7 +141,10 @@ function macaddr(val)
 end
 
 function hostname(val)
 end
 
 function hostname(val)
-       if val and (#val < 254) and val.match(val, "^[a-zA-Z0-9][a-zA-Z0-9%-%.]*[a-zA-Z0-9]$") then
+       if val and (#val < 254) and (
+          val:match("^[a-zA-Z0-9]+$") or
+          val:match("^[a-zA-Z0-9][a-zA-Z0-9%-%.]*[a-zA-Z0-9]$")
+       ) then
                return true
        end
        return false
                return true
        end
        return false
@@ -151,6 +154,10 @@ function host(val)
        return hostname(val) or ipaddr(val)
 end
 
        return hostname(val) or ipaddr(val)
 end
 
+function network(val)
+       return uciname(val) or host(val)
+end
+
 function wpakey(val)
        if #val == 64 then
                return (val:match("^[a-fA-F0-9]+$") ~= nil)
 function wpakey(val)
        if #val == 64 then
                return (val:match("^[a-fA-F0-9]+$") ~= nil)
@@ -267,3 +274,11 @@ function max(val, max)
 
        return false
 end
 
        return false
 end
+
+function neg(val, what)
+       if what and type(_M[what]) == "function" then
+               return _M[what](val:gsub("^%s*!%s*", ""))
+       end
+
+       return false
+end