diff options
author | Jo-Philipp Wich <jow@openwrt.org> | 2010-11-16 18:48:02 +0000 |
---|---|---|
committer | Jo-Philipp Wich <jow@openwrt.org> | 2010-11-16 18:48:02 +0000 |
commit | c20dcb3612de13eeb870de31d83e816d93bdc830 (patch) | |
tree | ac807d0631b39202598812f75c8939b21f589752 /libs/web/luasrc/cbi | |
parent | b17848e82e0a7fa482900559aaf5c3a11d3f07d9 (diff) |
libs/web: add range(min,max) datatype validator
Diffstat (limited to 'libs/web/luasrc/cbi')
-rw-r--r-- | libs/web/luasrc/cbi/datatypes.lua | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/libs/web/luasrc/cbi/datatypes.lua b/libs/web/luasrc/cbi/datatypes.lua index f8d815377..2fdb5802c 100644 --- a/libs/web/luasrc/cbi/datatypes.lua +++ b/libs/web/luasrc/cbi/datatypes.lua @@ -208,3 +208,15 @@ end function uciname(val) return (val:match("^[a-zA-Z0-9_]+$") ~= nil) end + +function range(val, min, max) + val = tonumber(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 |