Using JavaScript, I need to accept only numbers and commas.
The regex pattern I am using is as follows
var pattern = /^[-+]?[0-9]+(\.[0-9]+)?$/;
How do I accept commas in the above pattern So that values like 3200
or 3,200
or 3,200.00
and so are valid?
There are similar questions that only partially deal with this:
- Regex validation for numbers with comma separator (only whole numbers with no fractional part)
- Decimal number regular expression, where digit after decimal is optional (no comma separation, fractional part limited to 1 digit)
- Javascript function need allow numbers, dot and comma (the dots, commas and digits are matched in any order)