I have this code from a different code where i am trying to gigure out how can i add make this code as working additional method for my jquery validator
$.addMethod('allowing',{
validatorFunction: function (val, $el, conf) {
if (val !== '') {
var allowing = $el.valAttr('allowing') || '',
decimalSeparator = $el.valAttr('decimal-separator') || conf.decimalSeparator,
allowsRange = false,
begin, end,
steps = $el.valAttr('step') || '',
allowsSteps = false,
sanitize = $el.attr('data-sanitize') || '',
isFormattedWithNumeral = sanitize.match(/(^|[\s])numberFormat([\s]|$)/i);
if (isFormattedWithNumeral) {
if (!window.numeral) {
throw new ReferenceError('The data-sanitize value numberFormat cannot be used without the numeral' +
' library. Please see Data Validation in http://www.formvalidator.net for more information.');
}
//Unformat input first, then convert back to String
if (val.length) {
val = String(numeral().unformat(val));
}
}
if (allowing.indexOf('number') === -1) {
allowing += ',number';
}
if (allowing.indexOf('negative') === -1 && val.indexOf('-') === 0) {
return false;
}
if (allowing.indexOf('range') > -1) {
begin = parseFloat(allowing.substring(allowing.indexOf('[') + 1, allowing.indexOf(';')));
end = parseFloat(allowing.substring(allowing.indexOf(';') + 1, allowing.indexOf(']')));
allowsRange = true;
}
if (steps !== '') {
allowsSteps = true;
}
if (decimalSeparator === ',') {
if (val.indexOf('.') > -1) {
return false;
}
// Fix for checking range with floats using ,
val = val.replace(',', '.');
}
if (val.replace(/[0-9-]/g, '') === '' && (!allowsRange || (val >= begin && val <= end)) && (!allowsSteps || (val % steps === 0))) {
return true;
}
if (allowing.indexOf('float') > -1 && val.match(new RegExp('^([0-9-]+)\\.([0-9]+)$')) !== null && (!allowsRange || (val >= begin && val <= end)) && (!allowsSteps || (val % steps === 0))) {
return true;
}
}
return false;
},
errorMessage: '',
errorMessageKey: 'badInt'
});
but this function seems to be failing in all ends
please guide
do i need to follow somthing in this or i need to reformat this entire function to fix it