Join WhatsApp ChannelJoin Now

Input Allow Only Number In Jquery

Hi Dev,

Today, i we will show you input allow only number in jquery. This article will give you simple example of input allow only number in jquery. you will input allow only number in jquery. So let’s follow few step to create example of input allow only number in jquery.

Example:

<!DOCTYPE html>
<html>
<head>
    <title>Input Allow Only Number In Jquery</title>
    <script src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
</head>
<body>
  
<div class="container">
    <h1>Input Allow Only Number In Jquery</h1>
    <input type="text" name="number" class="number" autocomplete="off">
</div>
</body>
<script type="text/javascript">
    $('.number').keypress(function(event) {
      if ((event.which != 46 || $(this).val().indexOf('.') != -1) && (event.which < 48 || event.which > 57)) {
        event.preventDefault();
      }
    });
</script>
</html>

I hope it will assist you…

Recommended Posts