libs/web: add "neg()" cbi datatype to negate arbritary types, e.g. "neg(hostname)" would allow "!example.com"
This commit is contained in:
parent
704824c956
commit
794094caa2
2 changed files with 16 additions and 0 deletions
|
@ -218,6 +218,14 @@ var cbi_validators = {
|
||||||
if (!isNaN(max) && !isNaN(val))
|
if (!isNaN(max) && !isNaN(val))
|
||||||
return (val <= max);
|
return (val <= max);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
},
|
||||||
|
|
||||||
|
'neg': function(v, args)
|
||||||
|
{
|
||||||
|
if (args[0] && typeof cbi_validators[args[0]] == "function")
|
||||||
|
return cbi_validators[args[0]](v.replace(/^\s*!\s*/, ''));
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -267,3 +267,11 @@ function max(val, max)
|
||||||
|
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function neg(val, what)
|
||||||
|
if what and type(_M[what]) == "function" then
|
||||||
|
return _M[what](val:gsub("^%s*!%s*", ""))
|
||||||
|
end
|
||||||
|
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
Loading…
Reference in a new issue