Link to home
Start Free TrialLog in
Avatar of YZlat
YZlatFlag for United States of America

asked on

Need a regex for dollar amount validation

I have tried two regex expressions so far:

^\$?[0-9]+(\.[0-9][0-9])?$

Open in new window


and  

^\$?\d+(?:,\d+)*(?:.\d{2})?$

Open in new window


I need to validate dollar amounts with or without dollar sign, with or without decimal points and with or without commas.

The first one does not account for any commas, and the second one allows commas in the wrong places. Can anyone help me with a regex that would cover everything?
Avatar of kaufmed
kaufmed
Flag of United States of America image

^\$?\d{1,3}(,\d{3})*(\.\d\d)?$
ASKER CERTIFIED SOLUTION
Avatar of zzynx
zzynx
Flag of Belgium 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 YZlat

ASKER

Perfect! Thank you
You're welcome.
Thanx 4 axxepting