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

95
Vistas
How to restrict user from entering number in to an input field with type as text?

How to disable the user from entering a number in to input field . When we use type as number we are restricted from entering text in to the input .The same way how to achieve the vice versa . Someone help i need this to complete my assignment.

<input type="text" name="name" />
about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

You can add an input event listener to the input which gets the input's value, replaces every numeric character (with String.replace), then assigns the result back to the input's value:

const input = document.querySelector('input');
input.addEventListener('input', function(){
  this.value = this.value.replace(/[^\D]/g,'')
})
<input type="text" name="name" />

about 4 years ago · Juan Pablo Isaza Denunciar

0

You can listen to keydown, and if the key pressed is a number, just call event.preventDefault() on the keyboard event.

const input = document.querySelector('input');
input.addEventListener('keydown', function(event){
  if((/\d/g).test(event.key)) event.preventDefault();
})
<input type="text" />

about 4 years ago · Juan Pablo Isaza Denunciar

0

You can use 1 line function to prevent any number in the input with help of regular expression

But it is not recommended to use inline function , here is provided only to tell about a different approach

See here to know more about regular expression

<input type="text" name="name" oninput=" this.value = this.value.replace(/[0-9]/g,'')" />

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