Sat. Mar 28th, 2020


Codes for Coders

Number Keys Only

1 min read
jquery allow number keys only

jquery allow number keys only

This script allows users to type only Numeric values or Number Keys Only in any field.

Just call isNumberKey function on any field keypress.


<input type="text" onkeypress="return isNumberKey(event)" placholder="Mobile No."/>


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

Demo image

Leave a Reply

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