Regular Expressions 101

Community Patterns

Currency with $ symbol, support for commas

0

Regular Expression
PCRE (PHP <7.3)

/
^\$?(?:\d+|\d*\.\d+|(?:\d{1,3},)?(?:\d{3},)*\d{3}|(?:\d{1,3},)?(?:\d{3},)*\d{3}\.\d+)$
/
gmu

Description

Currency values that can include: $, dot (.), comma (,) and any number

Some valid examples

  • 1
  • 1234
  • 1,234
  • 1,234,567
  • 1.0
  • 1234.0
  • 1,234.0
  • 1,234,567.890
  • $.1
  • $1,234.567
  • 0.1234

Will not match any not-correctly formatted number with commas (US/Latam only, can be tweaked to accept other formats)

Submitted by Ricardo Vega - 7 years ago