Back to all patterns
Currency Amount Validation
Dates & Numbers
Validates US currency amounts like $1,234.56 or 1234.56.
/^\$?\d{1,3}(?:,\d{3})*(?:\.\d{2})?$/How it works
This pattern validates US-formatted currency amounts with optional dollar sign, optional thousands separators (commas), and optional two-decimal-place cents. It does not validate the currency symbol for other locales.
Test Cases
Should Match
- $1,234.56
- 1234.56
- $0.99
- 1,000,000
Should NOT Match
- $1.234,56
- 1234.567
- $-100
- abc
Quick Summary
Validates US currency amounts: optional $ prefix, digits with optional comma thousands separators, and optional two-decimal cents. Does not handle negative amounts or other currency symbols.
Key Takeaways
Key Takeaways
- Optional $ prefix
- Thousands separators (commas) are optional but must be in groups of 3
- Cents are optional but must be exactly 2 decimal places if present
- Does not handle negative amounts, add -? after ^ if needed
Use Cases
When to use it
- Validating price inputs in e-commerce forms
- Parsing currency values from financial reports
- Checking amount fields in payment API requests
Watch out
Common Mistakes
- Using this for non-US locales, European formats use . for thousands and , for decimals
- Not handling negative amounts for refunds or credits
FAQ
Currency Amount Validation, Frequently Asked
How do I validate currency for other locales?
Use the Intl.NumberFormat API to parse and format currency values per locale, rather than regex.
Should I store currency as a float?
No. Store currency as integers (cents) to avoid floating-point precision errors. $12.34 = 1234 cents.