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

137
Visualizações
Regex for input type="number" prevent enter plus character

I have a Regex for validation input type="number" but the problem with my regex that it allows to enter plus character, how to prevent enter plus symbol, but allow to enter minus? For example you can enter: 123; 11,22; -33; -33.44 but not allowed enter +123 and -0, +0

const deprecatedKeys = /^-+?\D$|^decimal$|^multiply$|^add$|^divide$|^subtract$|^spacebar$/i;
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The 1st part of your current pattern is problematic: ^-+?\D$ would currently match an hyphen between one and unlimited times but as few as possible and a non-digit character. So stuff like '-----+' or '-X' would match too.

If you want to allow for an optional leading hyphen and optional decimals, you could use:

^(?!-0$)-?\d+(?:[.,]\d+)?$

Furthermore, all these alternations could be grouped in a non-capture group with a single leading and trailing anchor:

^(?:(?!-0$)-?\d+(?:[.,]\d+)?|decimal|multiply|add|divide|subtract|spacebar)$
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