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

136
Vistas
How to get only 9 Digits before decimal and 2 digits after in a text box which only contains Decimal Value?

The below function I have created takes input in decimal only and maximum 12 char are allowed in it but it failed in 1 case where if user enters for example 12.45 and he/she again puts the cursor behind the decimal and start typing, it doesn't let the user enter though the capacity is 9 char before decimal and 2 after the decimal.

The Function is called on the keypress event.

Any help is appreciated Thanks!!

function isDecimalNumberWithOnlyNumbersandScaleTwoFunc(event) {

if (!event)
    event = window.event;
var charCode = (event.which) ? event.which : event.keyCode;
var elementValue = event.target.value;
if (event.key == "." && elementValue.indexOf('.') != -1) {
    event.preventDefault();
    return false;
}

if ((event.key == "." || isNumberKey(event))) {
    if ((event.key == "." || isNumberKey(event)) && (elementValue.substring(elementValue.indexOf('.'), elementValue.length).length <= 2)) {
        return true;
    }
    else if (isNumberKey(event)) {
        if ((elementValue.indexOf('.') != -1)) {
            event.preventDefault();
            return false;
        }
        else if (elementValue.length < 9) {
            if (isNumberKey(event) || event.key.toLowerCase() == "del" || event.key.toLowerCase() == "delete" || charCode == 46) {
                return true;
            }
            else
                return false;
        }
    }
    else if (event.key == ".") {
        return true;
    }
    event.preventDefault();
    return false;
}
else
    return false;

}

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