Jquery Allow Only Numbers and 2 Decimal in Textbox Tutorial




Hi Guys,

Today,I will learn you how to allow only numbers and 2 decimal in textbox in jquery. We will show example of jquery allow only numbers and 2 decimal in textbox. we will implement a how to allow only 2 digits after decimal in jquery.we willstep by step explain jquery allow only numbers with 2 decimal places. you can understand a concept of jquery allow only 2 decimal values in textbox.

I will take simple textbox and allow only enter float number with 2 decimal values. here i also added another example with allow only numbers and decimal in textbox jquery.


<!DOCTYPE html>



<title>Jquery Only Allow Input Float Number -nicesnippets.com/</title>

<script src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>



<div class="container">

<h1>Jquery Only Allow Input Float Number -nicesnippets.com/</h1>

<input type="text" name="number" class="number" autocomplete="off">



<script type="text/javascript">

$('.number').keypress(function(event) {

if ((event.which != 46 || $(this).val().indexOf('.') != -1) && (event.which < 48 || event.which > 57)) {






It will help you...