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

141
Visualizações
Input with numbers from -99 to 99

I have an input of type "text" where I want the user to be allowed to write inside just integers from -99 to 99.
The code so far is the following:

<input type="text" pattern="-?[0-9]{,2}" oninput="this.value=this.value.replace(/[^0-9\-]/g,'');">

The pattern returns valid=true even if the user just writes the minus sign (-) and this is not correct.
About the oninput, when the user writes a 3-digit number, the number remains in the field. The wanted behavior is to remove the third digit from the number.

Any ideas what to add to the pattern and the oninput in order to have correct results?


I have managed to do what I really wanted with a bit of JQuery.
Now the user can write ONLY numbers and the validity works as expected.
Here is the link: https://jsfiddle.net/panos78/2ctaonwL/
in case someone wants to see it how it works.

about 4 years ago · Juan Pablo Isaza
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