Amount Validator and Formatter Input Field - JavaScript

Author and Developer: Md. Nasir Uddin Bhuiyan (nubnasir@gmail.com)




Key note - version 1.0

  • Allows numbers 0-9, comma (,) and dot(.)
  • Adds comma(,) automatically in exact position
  • Prevents more that two(2) decimal points
  • No extra additional library is required

How to use

Step 1 download amount-1.0.min.js - click here to download

Step 2 Add amount-1.0.min.js at page <head> tag
<head>
<script type="text/javascript" src="amount-1.0.min.js"></script>
<head>

Step 3 In the amount input field add onkeyup="validAmountOnKeyUp(this)" and onkeypress="return validAmountOnKeyPress(this)"

<input type="text" onkeyup="validAmountOnKeyUp(this)" onkeypress="return validAmountOnKeyPress(this)">


Motivation

I have been working in fintech projects from a long time. While working with business people I have realized that they want to see financial items in a proper business format. Also they want to input amounts filed in a business format (like comma separated amounts field by only allowing two decimal points, etc). On the internet there is no complete article or guideline to validate and take input of amount field properly, and finance clients always want to input the amount field in a way where the user can feel that he/she is inputting an amount not a number or anything else. After realizing this I have decided to create an amount field input field where basic amount validations and auto formats are there. This The motivation behind creating a simple js to validate an auto format amount input field.

Released version
version - 2.0 (latest)
Documentation
Release date: 5th October 2020
Download amount-2.0.min.js (latest)
src | zip | tar.gz
version - 1.0
Documentation
Release date: 2nd October 2020
Download amount-1.0.min.js
src | zip | tar.gz