Quack
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
i.e.: 5,000.00 would be accepted as well as 5000.00 but not 5 or 50 or .50
(\d{1,3},)?(\d{3},)*\d+\.\d\d
Edit: allowed multiple digit groups separated by a comma.
HTH,
Dan
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
»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.
"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.
ASKER
Ok...here's what I have:
, Invoice_Amount: {
required: true
, pattern: /[0-9,]+\.[0-9][0-9]/
, min: .01
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"
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
»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?
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.
ASKER
closest to the solution
[0-9,]+\.[0-9][0-9]
»bp