Regex for Matching a Currency Amount
Matches a dollar amount with optional thousands separators and cents.
Published October 12, 2026
This regex matches currency amounts with optional $ sign, thousands separators and up to two decimals.
How the pattern works
Breaking the pattern down: \$? = optional dollar sign; \d{1,3}(,\d{3})* = digits with thousands commas; (\.\d{2})? = optional cents.
Test your regex against both matching and non-matching inputs; use the Regex tool on this site to experiment live.
Pattern tests
/^\$?\d{1,3}(,\d{3})*(\.\d{2})?$/
✓ '$1,234.56'
✓ '12'
✓ '1,000'
✗ '$12,34'
✗ '12.345'
Practical examples
The pattern
const re = /^\$?\d{1,3}(,\d{3})*(\.\d{2})?$/Test it
const re = /^\$?\d{1,3}(,\d{3})*(\.\d{2})?$/
re.test('$1,234.56') // true
re.test('12') // true
re.test('$12,34') // false
re.test('12.345') // falseIn Python
import re
re.search(r'^\$?\d{1,3}(,\d{3})*(\.\d{2})?$', text)Common mistakes
- Locale differences (1.234,56).
- Storing money as floats.
- Negative amounts.
Key takeaways
- Anchors (^ and $) make the whole string match instead of a part of it.
- Regex checks format only; verify data separately when it matters.
- Test with valid and invalid samples.
FAQ
Store money how?
As integer minor units or DECIMAL, not floats.
Where can I test this pattern?
Use the Regex Tester on this site, or regex101.com.