/^/
MediumNumbers4 min read

US Dollar Currency Regex

Validates a US dollar amount with a leading dollar sign, comma-grouped thousands, and an optional two-digit cents portion, such as $1,234.56.

#currency#usd#numbers#validation#money#forms

Regex Pattern

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

Pattern Breakdown

Hover over a token to see what it does.

^-?\$\d{1,3}(,\d{3})*(\.\d{2})?$
TokenMeaning
^Anchors the match to the start of the string.
-?An optional leading minus sign for a negative amount, placed before the dollar sign.
\$A required, escaped literal dollar sign.
\d{1,3}The first one to three digits of the whole-dollar amount.
(,\d{3})*Zero or more comma-separated groups of exactly three digits for thousands, millions, and so on.
(\.\d{2})?An optional cents portion: a dot followed by exactly two digits.
$Anchors the match to the end of the string.

Detailed Explanation

What it does

This pattern matches US-formatted currency amounts like $5, $0.99, $1,234.56, and -$5.00. It requires a dollar sign immediately after any leading minus sign, one to three leading digits, any number of additional comma-grouped three-digit clusters, and an optional cents portion of exactly two digits.

Why it works

Requiring the first digit group to be `\d{1,3}` and every subsequent group to be exactly `,\d{3}` mirrors how thousands separators are actually placed in US currency notation, so ungrouped numbers like $1234.56 correctly fail. The cents group is wrapped in `(\.\d{2})?` so whole-dollar amounts like $5 are still valid, but if a decimal point is present it must be followed by exactly two digits, not one or three.

Common use cases

  • Validating a price or payment amount field in an e-commerce checkout form
  • Parsing dollar amounts out of invoices, receipts, or financial reports
  • Pre-checking CSV exports of transaction data formatted as US currency strings
  • Filtering scraped text for strings that look like dollar amounts

Edge cases

  • $5 matches even without a cents portion, since the fractional group is optional
  • -$5.00 matches with the minus sign placed before the dollar sign, matching common US formatting
  • $1234.56 fails because thousands must be comma-grouped; ungrouped four-digit amounts don't match this pattern
  • $1,23.45 fails because the group after the comma has only two digits instead of the required three

Limitations

  • Only supports the US dollar sign and comma/period formatting convention, not other currencies or locales that swap the roles of comma and period
  • Does not enforce a maximum amount or check for reasonable value ranges
  • Does not accept ungrouped numbers, so a raw '$1234.56' without commas is rejected even though it's a valid amount

Interactive Tester

Edit the pattern or text below — matching runs live in your browser.

$1,234.56 $0.99 $5

Test Cases

Editable — add your own inputs to see if they pass.

InputExpectedResult
Pass
Pass
Pass
Pass
Pass
Pass
Pass
Pass

Language Variants

Production-ready examples in 12 languages.

const currencyPattern = /^-?\$\d{1,3}(,\d{3})*(\.\d{2})?$/;

function isUsdCurrency(value) {
  return currencyPattern.test(value);
}

console.log(isUsdCurrency("$1,234.56")); // true

Common Mistakes

Forgetting to escape the dollar sign, which is a regex anchor metacharacter and would silently break the pattern.

Fix: Always write it as `\$` so it's treated as a literal dollar sign rather than an end-of-string anchor.

Requiring exactly two decimal digits but then rejecting valid whole-dollar amounts like $5.

Fix: Wrap the cents portion in an optional group `(\.\d{2})?` so amounts with no cents still match.

Assuming ungrouped numbers like $1234.56 should match, then being confused when they don't.

Fix: Either insert commas before validating, or relax the pattern to `\d+` for locales that don't require thousands separators.

Performance Notes

  • The repeated `(,\d{3})*` group is bounded by realistic currency lengths in practice, so backtracking stays minimal for normal input sizes.
  • Anchoring both ends lets clearly malformed amounts fail immediately without scanning further.
  • For extremely large batch validation, precompile the regex once rather than constructing it inside a loop.

Browser Compatibility

EngineSupportedNotes
ChromeYes
FirefoxYes
SafariYes
EdgeYes
Node.jsYes