JS combination is to achieve the domestic mobile phone number section calibration _javascript skills

Source: Internet
Author: User

Append a Utils object, containing a check cell function, a formatted return data function

var ischinamobile =/^134[0-8]\d{7}$|^ (?: 13[5-9]|147|15[0-27-9]|178|18[2-478]) \d{8}$/; Mobile aspect of the latest response var ischinaunion =/^ (?: 13[0-2]|145|15[56]|176|18[56]) \d{8}$/; To Unicom micro-blog confirmed did not respond to var ischinatelcom =/^ (?: 133|153|177|18[019]) \d{8}$/; Section 1349th Telecommunications did not give a response, as does not exist var isothertelphone =/^170 ([059]) \d{7}$/;//other operators var utils = {Checkmobile:function (telpho
    NE) {telphone = This.trim (Telphone);
    if (Telphone.length!==) {return This.setreturnjson (false, ' no correct phone number detected ');
      } else{if (Ischinamobile.test (Telphone)) {return This.setreturnjson (true, ' move ', {name: ' Chinamobile '});
      else if (Ischinaunion.test (Telphone)) {return This.setreturnjson (true, ' Unicom ', {name: ' Chinaunion '});
      else if (Ischinatelcom.test (Telphone)) {return This.setreturnjson (true, ' telecom ', {name: ' chinatelcom '});
        else if (Isothertelphone.test (Telphone)) {var num = isothertelphone.exec (telphone); Return This.setreturnjson (True, "", {Name: "});
      else{return This.setreturnjson (False, ' no correct phone number detected ');  }}, Setreturnjson:function (Status, MSG, data) {if (TypeOf status!== ' Boolean ' && typeof status!==
    ' number ') {status = FALSE;
    } if (typeof msg!== ' string ') {msg = ';
  return {' Status ': Status, ' msg ': MSG, ' Data ': data};
 }
}

Verify the phone number of the 130-139,150-159,180-189 number section

<script type= "Text/javascript" >
var myreg =/^ (((13[0-9]{1}) | ( 15[0-9]{1}) | (18[0-9]{1})) +\D{8}) $/; 
if (!myreg.test ("#phone"). Val ()) 
{ 
  alert (' Please enter a valid cell phone number!) '); 
  return false; 
} 
</script>

The above code is debugged under jquery.

Code that doesn't require jquery

function Validatemobile (MOBILE) 
  { 
    if (mobile.length==0) 
    { 
     alert (' Please enter your mobile number! '); 
     Document.form1.mobile.focus (); 
     return false; 
    }   
    if (mobile.length!=11) 
    { 
      alert (' Please enter a valid cell phone number! '); 
      Document.form1.mobile.focus (); 
      return false; 
    } 
    
    var Myreg =/^ ((13[0-9]{1}) | ( 15[0-9]{1}) | (18[0-9]{1})) +\D{8}) $/; 
    if (!myreg.test (mobile)) 
    { 
      alert (' Please enter a valid cell phone number!) '); 
      Document.form1.mobile.focus (); 
      return false; 
    } 
  } 

The above mentioned is the entire content of this article, I hope you can enjoy.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.