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

139
Visualizações
How to accept only number in the input field using js

How to make the input box accept only numbers in the input field using js event listener.

  <form action="#">
     <label for="value">Value:</label>
     <input type="text" name="value" id="value" />
     <button type="submit">Convert</button>
     <button type="reset">Clear</button>
  </form>
 

<script>
    form.addEventListener(`submit`, function(event){
        event.preventDefault();
    });    
</script>
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can parse the input to a number and then check if it is a number or something else like NaN.

if(typeof parseInt(input) ==="number"){
  console.log("number!");
}

Please note that anyone can bypass this using the dev tools so don't forget to implemnt server-side validation.(Thx for the tip @samathingamajig)

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