Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

136
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!