How to allow only numbers in a text box using jQuery

If you have a form on a web page and you only want to allow numbers 0-9 to be input in the textbox and disallow any alphabets and other ASCII characters then you can do it easily using jQuery.

We will be using the keypress event and will bind our text box to it so that we can check which keys are being pressed by the user and then display those values which are acceptable for that textbox.

Enter your number:

Hope the above helped!

Be the first to comment

Leave a Reply