affiliate_link

Tuesday, June 16, 2009

How Can I Use Javascript to Allow Only Numbers?

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

return true;
}

Add the following to the onkeypress event of your text box

return isNumberKey(event)