Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

138
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda