summaryrefslogtreecommitdiffhomepage
path: root/libs/web/luasrc
diff options
context:
space:
mode:
authorJo-Philipp Wich <jow@openwrt.org>2012-06-25 09:51:59 +0000
committerJo-Philipp Wich <jow@openwrt.org>2012-06-25 09:51:59 +0000
commit6780f757d63e60f65a99ae4022f8b0d9c08fee94 (patch)
treede6037e7f7714af7569e2c25255265cf3e9a46e9 /libs/web/luasrc
parent66eec98a57e6e277c97e0e48b3a56b4813affba4 (diff)
libs/web: implement minlength(), maxlength() and rangelength() datatypes
Diffstat (limited to 'libs/web/luasrc')
-rw-r--r--libs/web/luasrc/cbi/datatypes.lua36
1 files changed, 35 insertions, 1 deletions
diff --git a/libs/web/luasrc/cbi/datatypes.lua b/libs/web/luasrc/cbi/datatypes.lua
index d3077f954..48586194a 100644
--- a/libs/web/luasrc/cbi/datatypes.lua
+++ b/libs/web/luasrc/cbi/datatypes.lua
@@ -17,7 +17,7 @@ local fs = require "nixio.fs"
local ip = require "luci.ip"
local math = require "math"
local util = require "luci.util"
-local tonumber, type, unpack, select = tonumber, type, unpack, select
+local tonumber, tostring, type, unpack, select = tonumber, tostring, type, unpack, select
module "luci.cbi.datatypes"
@@ -306,6 +306,40 @@ function max(val, max)
return false
end
+function rangelength(val, min, max)
+ val = tostring(val)
+ min = tonumber(min)
+ max = tonumber(max)
+
+ if val ~= nil and min ~= nil and max ~= nil then
+ return ((#val >= min) and (#val <= max))
+ end
+
+ return false
+end
+
+function minlength(val, min)
+ val = tostring(val)
+ min = tonumber(min)
+
+ if val ~= nil and min ~= nil then
+ return (#val >= min)
+ end
+
+ return false
+end
+
+function maxlength(val, max)
+ val = tostring(val)
+ max = tonumber(max)
+
+ if val ~= nil and max ~= nil then
+ return (#val <= max)
+ end
+
+ return false
+end
+
function phonedigit(val)
return (val:match("^[0-9\*#]+$") ~= nil)
end