Amount Field Validation Using JavaScript

When we work on any financial web application,we must use input field for amount value.

Amount is very important field in any form so it must be validate before submit.

This tutorial will help you  to understand how to validate amount field using JavaScript.


<input type="text" name="amount" id="field" onfocusout="checkAmount();"> 


function checkAmount() {
var myField = document.getElementById("field")
var reg = /^\d{0,4}(\.\d{0,2})?$/; if (reg.test(myField.value))
alert("Nice real currency!");
alert("Please Enter a Valid Amount!"); } }

With above script, amount input field value can be easily validated. If you have any questions regarding this article, feel free to comment.

Leave a Reply

Your email address will not be published. Required fields are marked *