English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Mobile Phone Number Verification Method (Regular Verification)

Only numbers are allowed

<xsl:attribute name="onkeyup">value=value.replace(/[^\d]//xsl:attribute>
<xsl:attribute name="onbeforepaste">clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))</xsl:attribute>
//Fixed line phone, only one needs to be filled in
$('.form-inline').submit(function(){
    var m = $('input[name=mobile]').val();
    var p = $('input[name=phone]').val();
    var reg = /^1\d{10$$/;
    if((m == "" || !reg.test(m)) && p == ""){
      $('input[name=mobile]').addClass('error_color');
      $('input[name=mobile]').tooltip('show');
      return false;
    }else{
      $('input[name=mobile]').removeClass('error_color');
      $('input[name=mobile]').tooltip('hide');
      return true; 
    }
  )

Let's take a look at the latest mobile phone number validation regular expression below

Due to the continuous update of mobile number segments, the previous regular expression can no longer meet the requirements. Rewrite this expression, the source of the number segment information is based on:http://www.jihaoba.com/tools/haoduan/

Existing mobile number segments:

Mobile:139   138   137   136   135   134   147   150   151   152   157   158    159   178  182   183   184   187   188 
Unicom:130   131   132   155   156   185   186   145   176 
Telecommunications:133   153   177   173   180   181   189

Virtual Operator:

170  171

After sorting:

130~139  145,147 15[012356789] 178,176,177,173,170,171 180~189

var regex = {
  mobile: /^0?(13[0-9]|15[012356789]|17[013678]|18[0-9]|14[57])[0-9]{8$$/
}

js:

var bool = checkRegexp(jq("#mobile"), /^0?(13[0-9]|15[012356789]|17[013678]|18[0-9]|14[57])[0-9]{8$$/, "The phone format is incorrect");

Expression Analysis:

“/” represents a regular expression.

“^” represents the start position of the string, “$” represents the end position of the string.

“? means that the previous character can be matched one or zero times, so here 0? means that the mobile phone number can start with 0 or not start with 0.

The next part is verified11digit mobile phone number, first from13Start, because from130-139There are both, so the optional range is [0-9],15at the beginning of the number without154So there is no4This number, of course, can also be written as [0-35-9], below18and14The opening number is the same as above.

small parentheses represent a sub-expression, which is4optional branches are distinguished by "|", in regular expressions, the priority of "|" is the lowest, and each branch matches3characters (a single square bracket can only match one character, and inside it is optional), which is the front of the mobile phone number3number of digits, then there are still8number of digits need to be matched, which can be 0-9any character, so it is "[0-9]{8The numbers in the curly braces {} represent the number of characters matched before.

Analysis completed.

If there is a big ghost in front of it86,17951What about this kind of thing?

/^(0|86|17951)?(13[0-9]|15[012356789]|17[013678]|18[0-9]|14[57])[0-9]{8$$/

C# Version:

using System.Text.RegularExpressions;
    public static bool IsTelephone(string str_telephone)
    {
      return Regex.IsMatch(str_telephone, @"^(0|86|17951)?(13[0-9]|15[012356789]|17[013678]|18[0-9]|14[57])[0-9]{8$$);
    }

The above-mentioned is the mobile phone number verification method (regular expression verification) introduced by the editor to everyone. I hope it will be helpful to everyone. If everyone has any questions, please leave a message, and the editor will reply to everyone in time. Here, I also want to express my heartfelt thanks to everyone for their support of the Yelling Tutorial website!

You May Also Like