Sun. Nov 17th, 2019

Codes

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.

HTML:


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

Scipt:


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 *