Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

229
Vistas
tratando de convertir una función de validación personalizada para agregar el complemento de validación jquery de validación

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?

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda