Closed
Description
I try to improve jQuery-Form-Validator until it can allow user to set the range of numbers from input type text data-validation="number".
Adding new format range[beginning_number;end_number] in data-validation-allowing="condition"
I modify the function that validate numbers become:
$.formUtils.addValidator({
name : 'number',
validatorFunction : function(val, $el, config) {
/* ............*/
if (allowing.indexOf('range') > -1)
{
var begin = parseFloat(allowing.substring(allowing.indexOf("[")+1, allowing.indexOf(";")));
var end = parseFloat(allowing.substring(allowing.indexOf(";")+1,allowing.indexOf("]")));
}
if(allowing.indexOf('number') > -1 && val.replace(/[0-9]/g, '') === '' && val >= begin && val <= end ) {
return true;
}
if(allowing.indexOf('float') > -1 && val.match(new RegExp('^([0-9]+)\\'+decimalSeparator+'([0-9]+)$')) !== null && val >= begin && val <= end ) {
return true;
}
}
/* ................... */
});
The range of numbers can be integer or float..
Hope that I can contribute this form-validator.