How to allow only numbers in Textbox using Jquery?

Admin   Jquery   453  2021-03-13 12:50:10

Hi Guys,

In this example,I will learn you how to use allow only number in textbox using can simply and easy to use validation for only number using jquery.

If you need to add jquery validation for your textbox like textbox should accept only numbers values on keypress event. you can also use keyup or keypress event to allow only numeric values in textbox using jquery.

I want to write very simple and full example so you can understand how it is working this example. you can also check demo.let' see bellow full example:

Example 1 :


<!DOCTYPE html>



<title>JQuery - Allow only numeric values in Textbox - </title>

<script src=""></script>



<div class="container">

<h1>JQuery - Allow only numeric values in Textbox - </h1>

<label>Enter Value:</label>

<input type="text" name="myValue" class="allow-numeric" >

<span class="error" style="color: red; display: none">* Input digits (0 - 9)</span>


<script type="text/javascript">

$(document).ready(function() {

$(".allow-numeric").bind("keypress", function (e) {

var keyCode = e.which ? e.which : e.keyCode

if (!(keyCode >= 48 && keyCode 57)) {

$(".error").css("display", "inline");



$(".error").css("display", "none");







It will help you....