Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

101
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda