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

200
Vistas
Can you add number padding to a bootstrap number input box?

If I'm using an input box, like so:

<input type="number" class="form-control" value="00001" />

How can I make it so that when pressing the arrow up, it changes to 00002 instead of 2?

enter image description here

Thanks!

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

"00001" or "00002" are not numbers, but if you still wanna do it, think something like:

Function to add leading zeros at left (num is value, size is the size of the string)

function padLeadingZeros(num, size) {
    var s = num+"";
    while (s.length < size) s = "0" + s;
    return s;
}

Then:

$(function() {
      $("input").change(function(e){ // If the value changes
            e.preventDefault();
            $(this).val(padLeadingZeros($(this).val(), 5)); //replace the value with the returned value of the function, 5 is size.
      });
});
about 4 years ago · Juan Pablo Isaza Denunciar
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