How to allow only 10 digit number validation in Jquery Example?

Today, We want to share with you 10 digit mobile number validation in jquery.In this post we will show you jquery validate phone number regex, hear for jquery validate phone number format we will give you demo and example for implement.In this post, we will learn about How To Allow Only 10 Digit Mobile Number Validation Using Javascript with an example.

Allow only 10 numbers in textbox using Jquery

Example 1: index.html

<!DOCTYPE html>
<html>
<head>
    <title>How to allow only 10 digit number validation in Jquery? - www.pakainfo.com</title>
</head>
<body>
<form>
    <h2>How to allow only 10 digit number validation in Jquery? - www.pakainfo.com</h2>
    <label>Numbers</label>
    <input type="text" name="num" placeholder="Enter numbers" pattern="\d{10}" maxlength="10">
    <button type="submit">Submit</button>
</form>
</body>
</html>


Example 2: index.html

<!DOCTYPE html>
<html>
<head>
    <title>How to allow only 10 digit number validation in Jquery? - www.pakainfo.com</title>
</head>
<body>
<form>
    <h2>How to allow only 10 digit number validation in Jquery? - www.pakainfo.com</h2>
    <label>Numbers</label>
    <input type="text" name="num" placeholder="Enter numbers" pattern="[1-9]{1}[0-9]{9}" maxlength="10">
    <button type="submit">Submit</button>
</form>
</body>
</html>

Example 3: index.html

<!DOCTYPE html>
<html>
<head>
    <title>How to allow only 10 digit number validation in Jquery? - www.pakainfo.com</title>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
</head>
<body>
<form>
    <h2>How to allow only 10 digit number validation in Jquery? - www.pakainfo.com</h1>
    <label>Moblie No</label>
    <input type="text" name="moblie_no" class="moblie-no" placeholder="Enter numbers">
  
    <button type="submit">Submit</button>
</form>
</body>
<script type="text/javascript">
   $("input[name=moblie_no]").attr("maxlength", "10");
  $('.moblie-no').keypress(function(e) {
      var arr = [];
      var kk = e.which;
   
      for (i = 48; i < 58; i++)
          arr.push();
   
      if (!(arr.indexOf(kk)>=0))
          e.preventDefault();
  });
</script>
</html>

I hope you get an idea about email and phone number validation in jquery.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.