Click here to Skip to main content
15,886,059 members
Articles / Programming Languages / Javascript
Article

Money Control Using JavaScript

Rate me:
Please Sign up or sign in to vote.
3.93/5 (5 votes)
20 Feb 20051 min read 29.9K   398   5  
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


Written By
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
-- There are no messages in this forum --