-1

I am using a regex for allowing only valid numeric list i.e. 123, 456, 12, 123456789, 12

And this regex is working fine for this. Now I just want that max one can input 5 digit number in the list like

12,34,12345,12 - correct

12,123,123456,1234 - incorrect because this list contains a number more than 5 digits.

^[0-9]+(,[0-9]+)*$

Right now I am using this upper regex. Can anyone modify this regex so it will give solution to my question? ( Only regex for javascript please)

Shikhil Bhalla
  • 392
  • 1
  • 5
  • 17

2 Answers2

1

Instead of using + which means "one or more characters", use curly braces to specify a specific number of characters:

^[0-9]{1,5}(,[0-9]{1,5})*$
Linda Paiste
  • 38,446
  • 6
  • 64
  • 102
0

\d for Numbers, shorter regex

^\d{1,5}$
Swordword
  • 151
  • 7