Click here to Skip to main content
Licence 
First Posted 20 Feb 2005
Views 22,185
Bookmarked 5 times

Money Control Using JavaScript

By | 20 Feb 2005 | Article
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

About the Author

Perumal Babu



India India

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
-- There are no messages in this forum --
Permalink | Advertise | Privacy | Mobile
Web04 | 2.5.120517.1 | Last Updated 21 Feb 2005
Article Copyright 2005 by Perumal Babu
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid