Regex for USD Currency
Regex Pattern
^\$?\d{1,3}(,\d{3})*(\.\d{2})?$US dollar amount with optional $ and thousands separators
Quick Answer
The regex pattern for usd currency is `^\$?\d{1,3}(,\d{3})*(\.\d{2})?$`. US dollar amount with optional $ and thousands separators. This works in JavaScript, Python, Ruby, PHP, Java, and most regex engines that support PCRE syntax.
Test Examples
| Input | Result |
|---|---|
| $1,234.56 | ✓ Matches |
| 1234.56 | ✓ Matches |
| $999 | ✓ Matches |
| 1,000,000.00 | ✓ Matches |
| 1.234,56 | ✗ No match |
| $1.2 | ✗ No match |
| $1,23.45 | ✗ No match |
Code Examples
javascript
const regex = /^\$?\d{1,3}(,\d{3})*(\.\d{2})?$/;
const isValid = regex.test(value);python
import re
pattern = r'^\$?\d{1,3}(,\d{3})*(\.\d{2})?$'
if re.match(pattern, value):
print("valid")ruby
pattern = /^\$?\d{1,3}(,\d{3})*(\.\d{2})?$/
if value =~ pattern
puts "valid"
endphp
if (preg_match('/^\$?\d{1,3}(,\d{3})*(\.\d{2})?$/', $value)) {
echo "valid";
}java
String pattern = "^\\$?\\d{1,3}(,\\d{3})*(\\.\\d{2})?$";
boolean isValid = value.matches(pattern);Frequently Asked Questions
Related Regex Patterns
Positive Integer
Integers greater than zero (no leading zeros)
Non-negative Integer
Zero or positive integer
Decimal Number
Optionally signed decimal number
Hex Color Code
3 or 6-digit hex color with optional #
Email Address
Validates a standard email address format
Email (RFC 5322 Compliant)
RFC 5322 compliant email validation with label length limits