loading...

10 digit mobile number validation in jquery

pakainfocom profile image pakainfo ・2 min read

In this Post,i shall say how you may allow only 10 numbers in textbox using jquery.we exactly allow only 10 digit number validation in jquery. guest may only enter 10 numbers in textbox using jquery for country code with phone number or mobile validation.

I will give you simple step by step all the example of how to restrict or required guest to type 10 digit numbers in input HTML element.we may do validation it that thing multiple way.We shall show different format of 10 digit mobile number validation using javascript with jquery

10 digit mobile number validation using javascript with jquery

The validating mobile number is best and an important point while validating an HTML form. In this Article we have all about the how to validate a mobile number (in different format) using HTML/JavaScript/jQuery :

One it using pattern attribute in html and another is maxlength and jquery keypress event. Therefor you may exactly display both example. You may display also source code bellow. You may use anyone as you want.

10 digit mobile number validation using javascript with jquery

index.html


li{list-style-type:none;font-size:16pt}.mail{margin:auto;padding-top:10px;padding-bottom:10px;width:400px;background:#d8f1f8;border:1px soild silver}.mail h2{margin-left:38px}input{font-size:20pt}input:focus,textarea:focus{background-color:#ffffe0}input submit{font-size:12pt}.rq{color:red;font-size:10pt}


function mobilenumber(userstrtxt)
{var phoneno=/^\d{10}$/;if(userstrtxt.value.match(phoneno))
{return true;}
else
{alert("Not a valid Phone Number");return false;}}

mobile number validation in jquery



   $("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();
  });

jquery mobile number validation

index.html

  
 
   
    $(document).ready(function() { 
      $('.error_Msg').hide(); 
      $('.submit').click(function(event){ 
        var data = $('.mobilephonenoval').val();  
         if(phone_validate(data)) 
         { 
           $('.error_Msg').hide();  
         } 
         else 
         { 
           $('.error_Msg').show();   
           event.preventDefault(); 
         } 
        }); 
     }); 
   
    function phone_validate(mobilephoneno) 
    { 
      var checkPattern =new RegExp(/^[0-9-+]+$/);
      return checkPattern.test(mobilephoneno); 
    } 
 
 
   
.error_Msg{ color:#fa4b2a; padding-left: 10px; } 
body{font-family:Verdana;}
 

You can visit my Article with More Examples : click here

Posted on by:

pakainfocom profile

pakainfo

@pakainfocom

My name is Angular King. I'm a full-stack developer, entrepreneur and owner of Pakainfo. I live in India and I love to write

Discussion

pic
Editor guide