How Can I Use Javascript to Allow Only Numbers?

[code]

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

return true;
}

[/code]

Add the following to the onkeypress event of your text box

[code]
return isNumberKey(event)
[/code]

Get Free Email Updates!

Signup now and receive free offers, discounts & coupon codes

I will never give away, trade or sell your email address. You can unsubscribe at any time.

Comments (1)
  1. Spencervag March 14, 2017

Leave a Reply

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

CommentLuv badge