Allow Numeric OR Numbers only using java script

Allow Numeric OR Numbers only using java script

I am going to explain here allow only numbers to be typed in a textbox i.e. numeric value or digits in TextBox using JavaScript. Also disabled the input via Dropping and Pasting the value. so that user not allow to directly drop or paste non numeric value in textbox


Numeric Value : <input type="text" id="amount" name="amount" onkeypress="return IsNumeric(event);" ondrop="return false;" onpaste="return false;" />

<span id="errormsg" style="color: Red; display: none">* Input digits (0 - 9)</span>


<script type="text/javascript">

var specialKeys = new Array();

specialKeys.push(8); //Backspace

function IsNumeric(e) {

var keyCode = e.which ? e.which : e.keyCode

var ret = ((keyCode >= 48 && keyCode <= 57) || specialKeys.indexOf(keyCode) != -1);

document.getElementById("errormsg").style.display = ret ? "none" : "inline";

return ret;




Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed