DD
DevDash

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

InputResult
$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"
end

php

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

Want API access + no ads? Pro coming soon.