Click here to Skip to main content
Click here to Skip to main content

Money Control Using JavaScript

By , 20 Feb 2005
Rate this:
Please Sign up or sign in to vote.

Introduction

In my recent project, we had a requirement to create a control that would accept the monetary values.

I thought this was a fairly simple requirement and thought I would get some code from the internet. But I was surprised to find that there was no free code available or may be I did not have the patience to find one.

I came up with my own control that is fairly simple but powerful. I decided to use JavaScript and HTML input box because it would fit into any web development script irrespective of the technology being used.

Money control using JavaScript

Basically, the work of the control is done by two functions. The first function HandleAmountFiltering is responsible for filtering all the keys pressed and allows only the numeric keys to be passed to the control. It also checks if the value in the control matches a regular expression. The second function FormatAmtControl fires when the control leaves the TextBox and is responsible for formatting the numbers to amount type. The Maxlength property of the control is used to fix the number of digits allowed before the decimal point.

An amount field always has two digits after the decimal point. The control ensures that there are two digits after the decimal point. This control also handles the “Over Flow” exceptions.

Hope this control would be of some use to people like me!

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Perumal Babu

India India
No Biography provided

Comments and Discussions

 
GeneralIndian Stock Market Tips by Bigprofitbuzz for Share Trading Tips Pinmemberbigprofitbuzz19-Mar-14 1:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web01 | 2.8.140421.2 | Last Updated 21 Feb 2005
Article Copyright 2005 by Perumal Babu
Everything else Copyright © CodeProject, 1999-2014
Terms of Use
Layout: fixed | fluid