[Solved] Regex Validator for element


Hello, is anyone able to assist with a regex to validate a comma separated dialog element. It would be a comma separated list of integers/numbers, each numbers need to be 2 or 3 digits, not more than 5 numbers and the sum total of the numbers no more than 500.

empty input is ok
10,20,30,40,50 is ok
100,20,20 is ok
10,2000 is bad (2000 is more than 3 digits)
5,10,300 is bad (5 is only one digit)
200,100,20,300 is bad (sum total is more than 500)
50,50,50,10,10,10 is bad (too many numbers more than 5)

I have tried ^\d{2,3}((,\d{2,3}){2,3})(\d{2,3})?$ and http://rubular.com/ but my regex experience is limited and I am not getting anywhere.




Should cover everything but the sum…
There is no way to test the sum with a single regex match, except for really mentioning all the possible valid combinations.


@himdel so awesome thanks. it was that last pesky digit i couldnt cover :face_with_raised_eyebrow: :+1:

i’ll let the regex validator do the heavy lifting and then use code to do the sum part. might have to go into a dynamic dialog of sorts…