A set of regular expressions that helps you validate and parse Money/Currency/Price values.
Currency amount with optional thousands separators, negative numbers, and two-digit fraction:
/^-?\d+(,\d{3})*(\.\d{1,2})?$/
Matches:
- 100
- -0.99
- 12,345,678.90
Currency amount (no thousands separators, must be positive, two-digit fraction):
/(?:^[1-9]([0-9]+)?(?:\.[0-9]{1,2})?$)|(?:^(?:0)$)|(?:^[0-9]\.[0-9](?:[0-9])?$)/
Matches:
- 100
- 0.99
- 1234567890
Validate US dollars including zero dollars.
^(\$)?(([1-9]\d{0,2}(\,\d{3})*)|([1-9]\d*)|(0))(\.\d{2})?$
Matches:
- $1,234,567.89
- 1234567.89
- $0.00
See Also:
Rate This Regex
User Review
( votes)Expression Flags
Flags | Description |
---|---|
i |
Ignore case sensitive. |
g |
Allows global search. |
m |
Allows multiline search. |