Numbers

US Currency (USD)

Matches USD currency amounts with optional $ sign, thousands separators, and cents.

Try it in RegexPro →

Available in

JavaScript / ECMAScript code

jsJavaScript
const re = new RegExp("^\\$?\\d{1,3}(,\\d{3})*(\\.\\d{2})?$", "");
const input = "$1,234.56";
const match = input.match(re);
console.log(match ? match[0] : null);

Uses `String.prototype.match`, which returns the first match or null.

Pattern

regexengine-agnostic
^\$?\d{1,3}(,\d{3})*(\.\d{2})?$

Raw source: ^\$?\d{1,3}(,\d{3})*(\.\d{2})?$

How it 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.56

Matches

  • $1,234.56

Input

999

Matches

  • 999

Input

$1000000.00

No match

—

Common use cases

  • •Invoice parsing
  • •Price validation
  • •E-commerce forms

Related patterns