Link to home
Start Free TrialLog in
Avatar of Quack
QuackFlag for United States of America

asked on

I need a regex for an invoice amount field to match N.NN format but allow commas

I need a regex for an invoice amount field to match N.NN format but allow commas:

i.e.: 5,000.00 would be accepted as well as 5000.00 but not 5 or 50 or .50
Avatar of Bill Prew
Bill Prew

This match one or more digits followed by a period, followed by two digits.

[0-9,]+\.[0-9][0-9]


»bp
(\d{1,3},)?(\d{3},)*\d+\.\d\d

Open in new window


Edit: allowed multiple digit groups separated by a comma.

HTH,
Dan
Avatar of Quack

ASKER

not working...throwing an error when 5,000.00 is put into the field: "The invoice amount must be greater than zero." any ideas?
My suggestion above works and should return "5,000.00", are you seeing something different?


»bp
Bill's solution will happily accept even  ,,5,,0,,,,,,,,,00,,,,,,0,,,0.00 as valid.

"The invoice amount must be greater than zero" has nothing to do with regex.
Show us the code where you use the regular expression and we might be able to help.
Avatar of Quack

ASKER

Ok...here's what I have:

			 , Invoice_Amount: {
				  required: true
				, pattern: /[0-9,]+\.[0-9][0-9]/
				, min: .01

Open in new window

Here's the pattern:
			, Invoice_Amount: {
				 required: "The Invoice Amount is a required field and may only contain numbers, and a decimal point."
				, pattern: "The Invoice Amount must match N.NN."
				, min: "The invoice amount must be greater than zero"

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Bill Prew
Bill Prew

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 Quack

ASKER

not sure...something's blocking it somewhere
I'm not a CF guy, but I added it to the topic list for this question in case a CF person might see something...


»bp
Hard to tell how/where this expression is used and whether it's a  CF or javascript issue.  

Can you post a small stand alone example?
seems like he is using a jquery validator,
Could be.  Though if it's not CF related, the question should be tagged Javascript to get help from the right audience.
Avatar of Quack

ASKER

closest to the solution