libs/web: add float and ufloat datatypes for field validation

This commit is contained in:
Jo-Philipp Wich 2010-12-05 00:19:09 +00:00
parent 8c9acb01f4
commit 090ce4f17e
2 changed files with 17 additions and 2 deletions

View file

@ -27,6 +27,16 @@ var cbi_validators = {
return (cbi_validators.integer(v) && (v >= 0)); 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) 'ipaddr': function(v)
{ {
return cbi_validators.ip4addr(v) || cbi_validators.ip6addr(v); return cbi_validators.ip4addr(v) || cbi_validators.ip6addr(v);

View file

@ -35,7 +35,7 @@ function bool(val)
return false return false
end end
function uint(val) function uinteger(val)
local n = tonumber(val) local n = tonumber(val)
if n ~= nil and math.floor(n) == n and n >= 0 then if n ~= nil and math.floor(n) == n and n >= 0 then
return true return true
@ -44,7 +44,7 @@ function uint(val)
return false return false
end end
function int(val) function integer(val)
local n = tonumber(val) local n = tonumber(val)
if n ~= nil and math.floor(n) == n then if n ~= nil and math.floor(n) == n then
return true return true
@ -53,6 +53,11 @@ function int(val)
return false return false
end end
function ufloat(val)
local n = tonumber(val)
return ( n ~= nil and n >= 0 )
end
function float(val) function float(val)
return ( tonumber(val) ~= nil ) return ( tonumber(val) ~= nil )
end end