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

105
Visualizações
Avoid enter dot in input field

I have an input field which is of number type, when I enter the dot I am not getting the value. So what I am trying to achieve is the I don't want the user to enter dot on the input field

function handleChange (value) {
 console.log(value)
}
<input type="number" onchange="handleChange(this.value)"/>

on each number entering I am getting the value, but when I type dot (.), I am not getting how can I block this when user type it

about 4 years ago · Santiago Gelvez
3 Respostas
Responde à pergunta

0

<input name="num" type="number" min="1" step="1" onkeypress="return event.charCode >= 48 && event.charCode <= 57">

referance from this url https://stackoverflow.com/a/44379790/4316212

about 4 years ago · Santiago Gelvez Relatório

0

Add This oninput="this.value = this.value.replace(/[^0-9]/, '')"

function handleChange (value) {
 console.log(value)
}
<input type="number" onchange="handleChange(this.value)" oninput="this.value = this.value.replace(/[^0-9]/, '')"/>

about 4 years ago · Santiago Gelvez Relatório

0

if you want to block '.' you can use this way,

function handleChange (value) {
console.log(value)
}

var inputBox = document.getElementById("inputBox");

var invalidChars = [
".",

];

inputBox.addEventListener("keydown", function(e) {
  if (invalidChars.includes(e.key)) {
    e.preventDefault();
  }
});
<input type="number" id="inputBox" onchange="handleChange(this.value)/>
about 4 years ago · Santiago Gelvez 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