Allow Only Numbers in Textbox

Javascript code allows only the numbers or numeric values to enter into the textbox.


  • Code accepts numerical value and restricts other values on every key press.
  • Performs validation for numbers entered in the textbox.
  • Simple, responsive and easy to integrate.


Allow Only Numbers in Textbox
Enter Number:


Script Code
<!-- Script by -->
<!-- More scripts -->

<script type="text/javascript">
function checnum(as){
var dd = as.value;


dd = dd.substring(0,(dd.length-1));
as.value = dd;



  • Release Date - 29-05-2015
  • Get free version without ©copyright link for just $10/-
  • For customization of this script or any script development, mail to


  • Copy and paste the javascript function inside the <head> tag of your HTML page.
  • Call "checnum()" function in the onkeyup event of your text box. ie., onkeyup="checnum(this)".
  • Here, the function "checnum()" is used to allow only numbers in the textbox.


Related Scripts

Free Javascript Scripts

Ask Questions

Ask Question