It needs to match these
- '42'
- '1,234'
- '6,368,745'
but not the following:
- '12,34,567' (which has only two digits between the commas)
- '1234' (which lacks commas)
I been using site such as http://www.regexpal.com/ to test out expressions.
I tried
^\d{1,3}(,\d{3})*$
(\d{1,3},)*(\d{1,3})$
([0-9]{1,3},)*([0-9]{1,3})$
[0-9]{1,3}((,[0-9]){1,3})*
but it doesn't work.
Could someone explain what's wrong with my attempts and an model answer?