Solved

validating currency input beyond hunderdth

Posted on 2012-12-20
2
289 Views
Last Modified: 2012-12-20
I have a jquery function that validates a value in US currency format.

j$.validator.addMethod("money", function(value, element) {
         return this.optional(element) || /^(\d{1,3})(\.\d{2})$/.test(value);
}, "Must be in US currency format 0.99");

Open in new window


This works for currency values from 0.01 up to 999.00, but it fails when a value of a thousand or more.  I'm not very good with regular expressions at all.

How can I modify the regex to correctly validate the value to support currency values up to 999,999.00?

Thanks for any help.
0
Comment
Question by:-Dman100-
2 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 38710542
Try:

return this.optional(element) || /^((?:\d{1,3},)?\d{1,3})(\.\d{2})$/.test(value);

Open in new window

0
 

Author Closing Comment

by:-Dman100-
ID: 38710910
Thank you!
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Form with Modals 16 55
REXEX help Part 2 2 22
How to position loader with CSS 3 36
parse a file and get data out 11 42
Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer …
Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question