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

165
Views
Regex for input with numbers and commas

I'm trying to limit input data.

My goal:

  • only two symbols per input allowed: numbers and a comma
  • first symbol only number (zero or more)
  • amount of numbers is unlimited (zero or more)
  • a dangling comma is allowed but only one

Test cases:

  • 1,2,4 - ок
  • 1221,212,4121212 - ок
  • ,2,3 - not ок
  • 1,2,3, - ок
  • 11,21111,31111, - ок

I've hade something like this but it doesn't work properly

/^\d*(,\d*)*$/.test(value)

Appreciate any help!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can use

/^(?:\d+(?:,\d+)*,?)?$/

See the regex demo. Details:

  • ^ - start of string
  • (?:\d+(?:,\d+)*,?)? - an optional non-capturing group:
    • \d+ - one or more digits
    • (?:,\d+)* - zero or more sequences of a comma and one or more digits
    • ,? - an optional comma
  • $ - end of string.
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!