Possible Duplicate:
Regular expression to match numbers with or without commas and decimals in text
var regex = /^[0-9][0-9]{0,5}$|^[0-9][0-9]{0,5}[\.][0-9]$/;
valid values are
3,000
30,000
looking to have comma in the above regex . I could not get it
This regex will test for commas being in the right place:
You can see a working example that validates as you type here: http://jsfiddle.net/jfriend00/u9VRX/
By way of explanation, the regex is:
If you don’t require commas and are going to parse the number anyway, then it’s easiest to just remove any commas first thus ignoring them:
If you want to know exactly what is wrong when it’s invalid, then that’s much more difficult to do with a pure regex. I would not find that the simplest way to solve the problem and it doesn’t generally tell you what is wrong with the number either so I would use some plain javascript first.
You can see this one working as you type here: http://jsfiddle.net/jfriend00/W6FnT/