Link to home
Start Free TrialLog in
Avatar of jxbma
jxbmaFlag for United States of America

asked on

What is a valid regex expression for currency?

Hi:

I'm trying to quickly figure out a regex for the following numeric value.

Essentially so it look like a valid currency
  - without commas (,)
  - or dollar signs ($)
  - greater than 0.00

We have uncovered something like this, but it doesn't seem to work:
([1-9]{1}[0-9]{0,2}(\,[0-9]{3})*(\.[0-9]{0,2})?|[1-9]{1}[0-9]{0,}(\.[0-9]{0,2})?|0(\.[0-9]{0,2})?|(\.[0-9]{1,2})?)

Open in new window


Thanks,
JohnB
ASKER CERTIFIED SOLUTION
Avatar of Qlemo
Qlemo
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jxbma

ASKER

I would like the two (2) decimal digits to be optional.

Thanks,
JB
This will allow no decimal digits and exact two (I don't think 190.1 makes sense):
'^[1-9]\d*(\.\d\d)?|^0.([1-9][0-9]|0[1-9])'
Avatar of jxbma

ASKER

Terrific!

I just extended it to be:    ^[1-9]\d*\.\d\d|^0.([1-9][0-9]|0[1-9])|^[1-9]\d*

Thanks,
JB