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.

HTML

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

JavaScript

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

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

READ ALSO :   How to restrict a textfield for certain character

Leave a Reply

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