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/htdocs/luci-static/resources/cbi.js | |
parent | b17848e82e0a7fa482900559aaf5c3a11d3f07d9 (diff) |
libs/web: add range(min,max) datatype validator
Diffstat (limited to 'libs/web/htdocs/luci-static/resources/cbi.js')
-rw-r--r-- | libs/web/htdocs/luci-static/resources/cbi.js | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/libs/web/htdocs/luci-static/resources/cbi.js b/libs/web/htdocs/luci-static/resources/cbi.js index 8e2f62aea2..059d27a1b9 100644 --- a/libs/web/htdocs/luci-static/resources/cbi.js +++ b/libs/web/htdocs/luci-static/resources/cbi.js @@ -155,6 +155,18 @@ var cbi_validators = { 'uciname': function(v) { return (v.match(/^[a-zA-Z0-9_]+$/) != null); + }, + + 'range': function(v, args) + { + var min = parseInt(args[0]); + var max = parseInt(args[1]); + var val = parseInt(v); + + if (!isNaN(min) && !isNaN(max) && !isNaN(val)) + return ((val >= min) && (val <= max)); + + return false; } }; @@ -634,6 +646,14 @@ function cbi_validate_reset(form) function cbi_validate_field(cbid, optional, type) { var field = (typeof cbid == "string") ? document.getElementById(cbid) : cbid; + var vargs; + + if( type.match(/^(\w+)\(([^\(\)]+)\)/) ) + { + type = RegExp.$1; + vargs = RegExp.$2.split(/\s*,\s*/); + } + var vldcb = cbi_validators[type]; if( field && vldcb ) @@ -649,7 +669,7 @@ function cbi_validate_field(cbid, optional, type) var value = (field.options && field.options.selectedIndex > -1) ? field.options[field.options.selectedIndex].value : field.value; - if( !(((value.length == 0) && optional) || vldcb(value)) ) + if( !(((value.length == 0) && optional) || vldcb(value, vargs)) ) { // invalid field.className += ' cbi-input-invalid'; |