Sometimes we need to create textboxes for accepting only numbers. For eg field for entering amount. In this case no characters are allowed, only numbers are needed to enter. In these type of cases we can use a simple javascript code to enable numbers only textboxes.
function isNumberKey(evt)
{
var charCode = (evt.which) ? evt.which : evt.keyCode;
if (charCode != 46 && charCode > 31
&& (charCode < 48 || charCode > 57))
return false;
return true;
}
function isNumber(evt) {
evt = (evt) ? evt : window.event;
var charCode = (evt.which) ? evt.which : evt.keyCode;
if (charCode > 31 && (charCode < 48 || charCode > 57)) {
return false;
}
return true;
}
This javascript can be written anywhere in the program page
<input id="amount" name="amount" type="text" onkeypress="return isNumberKey(event);" maxlength="8" class="form-control validate" required />
The highlighted portion should be added to the input tag.