JQuery – Allow only numeric values (numbers) in Textbox

JQuery – Allow only numeric values (numbers) in Textbox

In this post we will give you information about JQuery – Allow only numeric values (numbers) in Textbox. Hear we will give you detail about JQuery – Allow only numeric values (numbers) in TextboxAnd how to use it also give you demo for it if it is necessary.

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.

we will use keyCode for prevent to add string values. we will also accept numbers 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. i will attach demo link to bottom so you can check it. let’ see bellow full example:

Example:

Also see:How to disable f5 refresh button using jquery?

<!DOCTYPE html>

<html>

<head>

<title>JQuery - Allow only numeric values (numbers) in Textbox - ItSolutionStuff.com</title>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>

</head>

<body>

<div >

<h1>JQuery - Allow only numeric values (numbers) in Textbox - ItSolutionStuff.com</h1>

<label>Enter Value:</label>

<input type="text" name="myValue" >

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

</div>

<script type="text/javascript">

$(document).ready(function() {

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

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

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

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

return false;

}else{

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

}

});

});

</script>

</body>

</html>

I hope it can help you…

Hope this code and post will helped you for implement JQuery – Allow only numeric values (numbers) in Textbox. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github

Leave a Comment

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

7  +  2  =  

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US