Click here to Skip to main content
11,642,381 members (63,239 online)
Click here to Skip to main content

Money Control Using JavaScript

, 20 Feb 2005 25.4K 369 5
Rate this:
Please Sign up or sign in to vote.
Creating a control that accepts only monetary values.

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

Share

About the Author

Perumal Babu
India India
No Biography provided

You may also be interested in...

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150731.1 | Last Updated 21 Feb 2005
Article Copyright 2005 by Perumal Babu
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid