How to Allow Only 10 Digits Numbers in Textbox using JQuery?

Introduction

Have you ever encountered a situation where you wanted to restrict the input in a textbox to only 10-digit numbers? In this blog post, we will explore how to achieve this using JQuery, a popular JavaScript library. So, let’s dive in and learn how to implement this functionality in a simple and effective way!

Step 1:- Create a html page

<!DOCTYPE html>
<html>
<head>
    <title>Allow only 10 numbers in textbox using Jquery - wizbrand</title>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
</head>
<body> 
    
<form>
  <h1>Allow only 10 numbers in textbox using Jquery - wizbrand</h1>
  <input type="text" name="phone" placeholder="Phone..." maxlength="10" class="phone">
     
  <button type="submit">Submit</button>
</form>
    
</body>
    
<script type="text/javascript">
  $('.phone').keypress(function(e) {
      var arr = [];
      var kk = e.which;
   
      for (i = 48; i < 58; i++)
          arr.push(i);
   
      if (!(arr.indexOf(kk)>=0))
          e.preventDefault();
  });
</script>
</html>

Output:-

Related Posts

Launching Your Aviation Career: How to Select the Right Flight School

Entering the aviation sector is an extraordinary milestone for anyone who has ever looked upward and envisioned a life in the cockpit. Whether your ambition is to…

Read More

The Definitive Handbook on Selecting Orthopedic Hospitals and Practitioners

Deciding where to seek treatment for an aching joint, an old sports injury, or persistent back pain is a pivotal moment in personal healthcare. Musculoskeletal concerns span…

Read More

Finding Reliable Legal Representation and Professional Guidance Online

Navigating personal or professional life often brings moments where legal clarity becomes essential. Whether someone is finalizing a real estate acquisition, managing a boundary disagreement, navigating marital…

Read More

Ask a Doctor Online: A Simple Guide to Virtual Healthcare

In our fast-paced world, the traditional trip to a doctor’s office isn’t always the most practical first step when health concerns arise. Whether you are dealing with…

Read More

Best Free Programming Ebooks to Learn Software Development

Learning modern technology can feel overwhelming when tutorials are scattered across dozens of websites. Many software developers, engineering students, and IT professionals struggle to find comprehensive study…

Read More

FinOps Training: Understanding Cost Visibility and Optimization

Introduction Moving workloads to the cloud can simplify infrastructure management, but it can also introduce a new financial challenge. Teams can provision resources whenever they need them,…

Read More
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x