From 090ce4f17e13e81a459e1ef0e9d6db974d97579c Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Sun, 5 Dec 2010 00:19:09 +0000 Subject: libs/web: add float and ufloat datatypes for field validation --- libs/web/htdocs/luci-static/resources/cbi.js | 10 ++++++++++ libs/web/luasrc/cbi/datatypes.lua | 9 +++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) (limited to 'libs/web') diff --git a/libs/web/htdocs/luci-static/resources/cbi.js b/libs/web/htdocs/luci-static/resources/cbi.js index 3959b6937..992b5588e 100644 --- a/libs/web/htdocs/luci-static/resources/cbi.js +++ b/libs/web/htdocs/luci-static/resources/cbi.js @@ -27,6 +27,16 @@ var cbi_validators = { return (cbi_validators.integer(v) && (v >= 0)); }, + 'float': function(v) + { + return !isNaN(parseFloat(v)); + }, + + 'ufloat': function(v) + { + return (cbi_validators['float'](v) && (v >= 0)); + }, + 'ipaddr': function(v) { return cbi_validators.ip4addr(v) || cbi_validators.ip6addr(v); diff --git a/libs/web/luasrc/cbi/datatypes.lua b/libs/web/luasrc/cbi/datatypes.lua index 2fdb5802c..62f06c4b4 100644 --- a/libs/web/luasrc/cbi/datatypes.lua +++ b/libs/web/luasrc/cbi/datatypes.lua @@ -35,7 +35,7 @@ function bool(val) return false end -function uint(val) +function uinteger(val) local n = tonumber(val) if n ~= nil and math.floor(n) == n and n >= 0 then return true @@ -44,7 +44,7 @@ function uint(val) return false end -function int(val) +function integer(val) local n = tonumber(val) if n ~= nil and math.floor(n) == n then return true @@ -53,6 +53,11 @@ function int(val) return false end +function ufloat(val) + local n = tonumber(val) + return ( n ~= nil and n >= 0 ) +end + function float(val) return ( tonumber(val) ~= nil ) end -- cgit v1.2.3