Regular Expressions
Metacharacters - Quantifiers
{min,max}
/^[0-9]{1,3},?[0-9]{3}$/

1,247
32,456
673419
4-6 Digits with optional comma.
Tux the Linux Penguin.