Block Alphabet in text field using JavaScript

In this article, I will demonstrate how to allow user to input only numeric characters in a TextBox field by using Javascript. The program prevents user from copying and pasting invalid characters into the TextBox.


function isNumberKey(evt) {
var charCode = (evt.which) ? evt.which : event.keyCode
if (charCode > 31 && (charCode < 48 || charCode > 57) && charCode != 46)
return false;
return true;
}

Leave a Reply

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

15 + 13 =