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.
Regex Pattern
^-?\$\d{1,3}(,\d{3})*(\.\d{2})?$Pattern Breakdown
Hover over a token to see what it does.
| Token | Meaning |
|---|---|
| ^ | 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.
Test Cases
Editable — add your own inputs to see if they pass.
| Input | Expected | Result | |
|---|---|---|---|
| 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")); // trueCommon 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
| Engine | Supported | Notes |
|---|---|---|
| Chrome | Yes | — |
| Firefox | Yes | — |
| Safari | Yes | — |
| Edge | Yes | — |
| Node.js | Yes | — |
Work with this pattern
Take this expression further — test it against your own data, adapt it in the builder, or read up on the syntax behind it.
Regex Tester
Test a regular expression against sample text and see every match highlighted live.
Regex Generator
Build a pattern by clicking blocks — no syntax memorisation required.
Regular Expressions Guide
What regex is, how the syntax works, and the mistakes that trip people up.
Regex Cheat Sheet
Every token, quantifier, and assertion on one printable page.
Python Regex Guide
The re module end to end — search, match, findall, groups, and substitution.
Regex Pattern Library
100+ ready-to-use patterns for email, URLs, dates, IPs, and more.