JS regular expression to verify whether it is a valid 11-digit mobile phone number,

https://blog.csdn.net/nongweiyilady/article/details/74007124

 

Recently, I have been working on the registration and landing page, which involves the verification of 11-digit valid mobile phone numbers. The code is posted here, hoping to help friends who have this development needs.

[javascript] view plain copy
  1. function isPoneAvailable($poneInput) {  
  2.           var myreg = / ^ [1] [3,4,5,7,8] [0-9] {9} $ /;  
  3.           if (!myreg.test($poneInput.val())) {  
  4.               return false;  
  5.           } else {  
  6.               return true;  
  7.           }  
  8.       }  


Here I directly encapsulate it in a method, and when needed, pass in an input jq object. Of course, you can also pass in strings directly, like:

[javascript] view plain copy
  1. function isPoneAvailable(str) {  
  2.           var myreg = / ^ [1] [3,4,5,7,8] [0-9] {9} $ /;  
  3.           if (!myreg.test(str)) {  
  4.               return false;  
  5.           } else {  
  6.               return true;  
  7.           }  
  8.       }  

The point here is this regular expression:

[javascript] view plain copy
  1. var myreg = / ^ [1] [3,4,5,7,8] [0-9] {9} $ /;  

This expression means:

1--begins with 1;

2--The second digit can be any one of 3, 4, 5, 7, 8;

3--finally ends with 9 integers from 0-9.

 

Originally, it only accommodates mobile phone numbers starting with 13, 15, 17, 18, but the test mm says that there are numbers starting with 14, so 14 is added; of course, if it develops into numbers starting with 16, or 19, etc. ,exist

[javascript] view plain copy
  1. [3,4,5,7,8]  

can be added in.

Pro test feasible 20180428

 

 

2017-9-8 

[javascript] view plain copy
    1. // Determine whether it is a mobile phone number  
    2.  isPoneAvailable: function (pone) {  
    3.    var myreg = / ^ [1] [3,4,5,7,8] [0-9] {9} $ /;  
    4.    if (!myreg.test(pone)) {  
    5.      return false;  
    6.    } else {  
    7.      return true;  
    8.    }  
    9.  },  
    10.  // Determine if it is a phone number  
    11.  isTelAvailable: function (tel) {  
    12.    var myreg = /^(([0\+]\d{2,3}-)?(0\d{2,3})-)(\d{7,8})(-(\d{3 ,}))?$/;  
    13.    if (!myreg.test(tel)) {  
    14.      return false;  
    15.    } else {  
    16.      return true;  
    17.    }  
    18.  }, 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325024702&siteId=291194637