Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

format currency - regex 1

Status
Not open for further replies.

tester321

Programmer
Joined
Mar 13, 2007
Messages
150
Location
CA
Hi, the search functionality in this fourm(s) are not working, sure this has been done prior, sry for the redundancy if so.

I have a variable that can be:

10.1 or 5 or 5.00

I would like to format this as money, this is what i have so far, am not good with javascript, thanks for the help!

fMoney = function(str) {
var re = new RegExp(str);

document.getElementById("subtotal").innerHTML = /^\$?[1-9][0-9]{0,2}(,[0-9]{3})*(\.[0-9]{2})?$/;

}
 
You were trying to set the innerHTML of your object to a regular expression, which does not logically make sense. Regular expressions are used to find matches in strings, so all you'd use the regex for is to check if your string is formatted a certain way, not to apply the formatting. Dan's solution is best - use toFixed

-kaht

Looking for a puppy? [small](Silky Terriers are hypoallergenic dogs that make great indoor pets due to their lack of shedding and small size)[/small]
 
Thanks All!

khat, yes I know i was trying to do that, i was trying to test a true or false on the regex. Thanks BillyRayPreachersSon for understang my intensions! cheers to all ?
 
khat, yes I know i was trying to do that, i was trying to test a true or false on the regex.

You'd have to use some sort of method to pull that kind of data (for example,the test method returns a boolean value based on the match of the string parameter).

-kaht

Looking for a puppy? [small](Silky Terriers are hypoallergenic dogs that make great indoor pets due to their lack of shedding and small size)[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top