EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: devnull on April 06, 2016, 07:19:01 PM



Title: [Solved] validType numeric < = != > etc
Post by: devnull on April 06, 2016, 07:19:01 PM
[Solved] How can I set a ValidType on a numberbox / numberspinner that will validate the value i.e:

validType:['value[!=100.222]']
validType:['value[> 1000]']
validType:['value[> 1000 < 2000]']



Title: Re: validType numeric < = != > etc
Post by: stworthy on April 06, 2016, 07:46:09 PM
Please refer to the following code:
Code:
$.extend($.fn.validatebox.defaults.rules, {
range: {
validator: function(value, param){
value = parseFloat(value);
var min = parseFloat(param[0]);
var max = parseFloat(param[1]);
if (value > min && value < max){
return true;
}
return false;
},
message: 'Invalid number.'
},
notequal: {
validator: function(value, param){
value = parseFloat(value);
var v = parseFloat(param[0]);
return value != v;
},
message: 'The value can not equal to {0}'
}
})
$(function(){
$('#ns').numberspinner({
validType: {
range: [1000,2000],
notequal: [1002]
}
})
})


Title: Re: validType numeric < = != > etc
Post by: devnull on April 06, 2016, 08:01:37 PM
Thanks, yes that works, but I was thinking more along the lines of using eval() although I know this function is potentially dangerous.