Regular Expressions 101

Community Patterns

Community Library Entry

1

Regular Expression
PCRE2 (PHP >=7.3)

/
^(?!-)\d{1,3}(?:,\d{3})*(?:\.\d{2})?$
/
mg

Description

I use this for validation on an input. Currency input that must include comma separation. Decimal places, 2, optional. No minus sign or currency symbols allowed. Valid: 1,000 1,234.56 1,234,555

Not valid: 1000 123.4 $230 -60.00 60000 10.

Submitted by Truper - 22 days ago