US Currency (USD) in JS
Matches USD currency amounts with optional $ sign, thousands separators, and cents.
Try it in the JS tester →Pattern
regexJS
^\$?\d{1,3}(,\d{3})*(\.\d{2})?$JavaScript / ECMAScript code
jsJavaScript
const re = new RegExp("^\\$?\\d{1,3}(,\\d{3})*(\\.\\d{2})?$", "");
const input = "$1,234.56";
const matches = [...input.matchAll(re)];
console.log(matches.map(m => m[0]));Uses `String.prototype.matchAll` for global iteration (Node 12+ / all modern browsers).
How the pattern works
`^\$?` optional dollar sign. `\d{1,3}(,\d{3})*` matches the integer part with optional comma-separated thousands. `(\.\d{2})?` optional cents.
Examples
Input
$1,234.56Matches
$1,234.56
Input
999Matches
999
Input
$1000000.00No match
—