Solved

validating currency input beyond hunderdth

Posted on 2012-12-20
2
285 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 74

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
Comment Utility
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-
Comment Utility
Thank you!
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Whatever be the reason, if you are working on web development side,  you will need day-today validation codes like email validation, date validation , IP address validation, phone validation on any of the edit page or say at the time of registration…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

763 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now