Tengo este código de un código diferente en el que estoy tratando de averiguar cómo puedo agregar este código como método adicional de trabajo para mi validador jquery
$.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' });
pero esta función parece estar fallando en todos los extremos
por favor guía
¿Necesito seguir algo en esto o necesito reformatear toda esta función para solucionarlo?