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

172
Vistas
Rejecting non digits in vue input

Does somebody knows how to implement a VUE input field that rejects entering non digits as the user tries to enter it.

Some kind of:

<b-form-input v-on:keypress="onlyNumber(...."

Thanks!

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

0

The easiest way would be to declare the input type to number. <b-form-input type="number" ...

about 4 years ago · Juan Pablo Isaza Denunciar

0

Finally, for me, this do the job:

    <input v-on:keydown="onlyNumber($event)" ... />

    

onlyNumber: function(evt) { //0035621
        evt = (evt) ? evt : window.event;
        var charCode = (evt.which) ? evt.which : evt.keyCode;
        if (charCode > 31 && (charCode != 46 &&(charCode < 48 || charCode > 57))) {
            evt.preventDefault();
        } else {
            return true;
        }
    }
about 4 years ago · Juan Pablo Isaza Denunciar

0

You can use keyCode of the key pressed on keydown event and perevent default behavior if keyCode isn't for a non digit key;

Vue input component:

<b-form-input @keydown="onlyNumbers" />

And the onlyNumbers method would be:

onlyNumbers(e) {
    if((e.keyCode < 48 || e.keyCode > 57) && (e.keyCode < 96 || e.keyCode > 105)) {
        e.preventDefault();
}

Related Links: keyCode values for numeric keypad, preventDefault, Keydown Event

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