I want to check whether given input is valid integer range.
[0-9]-{1}[0-9]
The above regex not working for some cases.
Example:
10 // false. - working as expected
10-20 // true. - working as expected
h-g // false. - working as expected
10-20- // true. - should be false
10-20-30 // true. - should be false
Update 2: Check for comma(,) separated input
Now the same input text field can allow comma(,) separated input as well. Eg. 10,20,30 also allowed. rangePattern = new RegExp('^[0-9]*,[0-9]*$')
; is not allowing me to give more than one comma. How to allow repentance.
Example:
10,20 valid.
10,20,30 valid.
10,20, invalid.
10,20-30 invalid.
Update 3: regex /^(\d+,)*\d+$/
not working for input 10,,,20
How to resolve this?
Solved:
{1} - allow only once.
regex should be /^(\d+,{1})*\d+$/