JQuery Allow Only Numbers Input in Textbox

JQuery Allow Only Numbers Input in Textbox

Today, We want to share with you JQuery Allow Only Numbers Input in Textbox.
In this post we will show you Allow only numeric input in textbox using jQuery, hear for Enter Only Numbers and Decimal Values Using jQuery we will give you demo and example for implement.In this post, we will learn about jQuery – Allow Only Numbers (Numerics) in Textbox with an example.

Now in this post, I will explain how to Allow Only Numbers in Textbox using JQuery with appropriate example. Many a times you want only numeric value in textbox like Count of something, Phone number ,Computer Port etc. In such a situation you can use Jquery to alllow only numeric value by writting below code.

Read Also:  How to validate phone numbers using jquery?

jquery Count Number of characters in string input

First Of all add textbox control in  your html.

<input type="text" id="txtOnlyNumber">

Now write below lines in JavaScript file or include it in script section of above html file.

$(function () {
$('#txtOnlyNumber').keydown(function (e) {
if (e.shiftKey || e.ctrlKey || e.altKey) {
} else {
var key = e.keyCode;
if (!((key == 8) || (key == 46) || (key >= 35 && key <= 40) || (key >= 48 && key <= 57) || (key >= 96 && key <= 105))) {

Allow Only Numbers in Textbox using JQuery

Read Also:  how to convert php page to pdf using php?

Read :


You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about How to allow only numeric values ( numbers ) in a TextBox using jQuery.I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.