Latest phone number, phone number regular expression _ regular expression

Source: Internet
Author: User

Today began a small series for everyone to organize a series of regular expression of the article, I hope you will like.

First understand the concept of regular expressions, the regular expression (regular expression) describes a pattern of string matching that can be used to check whether a string contains a seed string, to replace a matching substring, or to remove a substring from a string that matches a condition.

Java phone number Regular expression:

 /**
  * Verify mobile phone number
  * 
  * mobile number: 139, 138, 137, 136, 135, 134, 150, 151, 152, 157, 158, 159, 182, 183, 187, 188, 147
  * Unicom Number: 130, 131, 132, 136, 185, 186, 145
  * Telecommunications Number: 133, 153, 180, 189 * * 
  @param cellphone * *
  @return *
  Public
 Static Boolean Checkcellphone (String cellphone) {
 string regex = ' ^ ((13[0-9]) | ( 14[5|7]) | (15 ([0-3]|[ 5-9]) | (18[0,5-9]) \\d{8}$ "; 
 Return check (cellphone, regex);
 }

 /**
  * Verify fixed number
  * * 
  @param telephone
  * @return
 /public static Boolean Checktelephone ( String telephone) {
 string regex = ' ^ (0\\d{2}-\\d{8} (-\\d{1,4})?) | (0\\d{3}-\\d{7,8} (-\\d{1,4})?) $";
 return check (telephone, regex);
 }

PHP Phone number Regular expression

<?php 
//Regular expression 
$tel = "15558530459";//Mobile phone number
if (strlen ($tel) = = "One") 
{ 
//The upper part of the judgment length is not 11 bit 
$ n = Preg_match_all ("/13[123569]{1}\d{8}|15[1235689]\d{8}|188\d{8}/", $tel, $array); 
/* The next regular expression ("/131,132,133,135,136,139 followed by any 8 for the number ' | ') (or meaning) 
* 151,152,153,156,158.159 the beginning of the following arbitrary 8 for the number 
* or 188, followed by any 8 of the number, matching any of the group passed the 
*/") * */ 

Var_dump ($array); See if it's found, and if it does, it will output the phone number 
}else 
{ 
echo length must be 11 bits; 
} 
* * Although it looks more complex, clear understanding! 
* If there is a better, you can post it, share happiness! 
* * * */ 
?> 

JS Phone number Regular expression

function Checkmobile () { 
 var smobile = Document.mobileform.mobile.value 
 if (!) ( /^1[3|4|5|8][0-9]\d{4,8}$/.test (Smobile)) { 
  alert ("Not a full 11-digit cell phone number or the correct number of the top seven"); 
  Document.mobileform.mobile.focus (); 
  return false; 
 } 
} 

The following is the cloud Habitat Community editors on the above regular expression of the simple analysis, with the increase in the number of mobile phone numbers, we can expand their own functions, do not know the regular friends read this article should be a point ah.
This is mainly the code, and later we modify this paragraph can be.
^1[3|4|5|8][0-9]\d{4,8}$
^1 representative to start with 1, now China's mobile phone number is not the other beginning, later not necessarily AH
[3|4|5|8] immediately after the top 1, can be 3 or 4 or 5 or 8 of a number, if the next 190 start cell phone number, you need the following [3|4|5|8| 9]
[0-9] represents any number in the middle of 0-9, which can be 0 or 9
\d{4,8} This \d, like [0-9], is a number in the middle of 0-9. {4,8} represents the highest 8 digits of the previous minimum 4-digit number. Why here is not the direct 8, because the cell phone number attribution to the query, according to the first 7 can know the specific address, the following 4-bit has no impact.

About JS mobile phone number verification for you to recommend a few small examples:
Example 1:
Mobile phone number Verification

String.prototype.isTel = function ()
{
//"compatible format: Country code jb51.net (2 to 3 bits)-area code (2 to 3 digits)-Phone number (7 to 8 digits)-EXT (3)"
// Return (/^ ([0+]d{2,3}-)? ( 0d{2,3})? (d{7,8}) (-(D{3,}))? $/.test (this. Trim ());
Return (/^ ([0+]d{2,3}-)? ( 0d{2,3})-(d{7,8}) (-(D{3,})? $/.test (this. Trim ());
}
Verify the phone number
String.prototype.isMobile = function () {return
(/^ (?: 13d|15[89])-?d{5} (D{3}|*{3}) $/.test (this. Trim ());

}

Telephone number Verification

function Checknum () {//call validation
var Inputvalue=document.gsjbxxbean.dh.value;
var reg=/^ ([0-9]|[ -] +$/g;
var isValid
isvalid=reg.exec (inputvalue)
if (!isvalid) {return
false
} return
true
}

Example 2:
Verify your phone number
Validation rule: 11 digits, beginning with 1.

function 
 Checkmobile (str) {
 var 
 re =/^1\d{10}$/
 if (re.test (str)) {
  alert ("correct");
 } else {
  alert (' Error ');
 }
}
Checkmobile (' 13800138000 '); Call
checkmobile (' 139888888889 ');//Error example

Verifying phone numbers
Validation rules: Area code + number, area code starting with 0, 3-bit or 4-bit
The number consists of 7-digit or 8-digit digits.
There can be no connector between the area code and the number, or you can "-" Connect
such as 01088888888,010-88888888,0955-7777777

function
 Checkphone (str) {
 var
 re =/^0\d{2,3}-?\d{7,8}$/;
 if (Re.test (str)) {
  alert ("correct");
 } else{
  alert ("error");
 }
Checkphone ("09557777777");

Add:
Regular expression--verification of mobile phone number: 13[0-9]{9}
To achieve the mobile phone number 86 or +86 before: ^ (\+86) | (86))? (\d{9}$)
The phone number and mobile number are verified simultaneously: (^ (\d{3,4}-) \d{7,8}) $| (13[0-9]{9})
To extract the network links in the information: (h| H) (r| R) (e| E) (f| F) *= * (' | ')? (\w|\\|\/|\.)  +('|"| *|>)?
Message address in the extraction information: \w+ ([-+.] \w+) *@\w+ ([-.] \w+) *\.\w+ ([-.] \w+) *
Extract picture links in information: (s| S) (r| R) (c| C) *= * (' | ')? (\w|\\|\/|\.)  +('|"| *|>)?
Extract the IP address in the information: (\d+) \. (\d+) \. (\d+) \. (\d+)
China Mobile phone number to extract information: (*0*13\D{9)
Extract Chinese fixed phone number in information: (\ (\d{3,4}\) |\d{3,4}-|\s)? \d{8}
Extract the Chinese phone number (including mobile and landline) in the information:(\ (\d{3,4}\) |\d{3,4}-|\s)? \d{7,14}
China Post Code in Extract information: [1-9]{1} (\d+) {5}
Chinese identity card number in the extraction of information: \d{18}|\d{15}
To extract an integer from the information: \d+
Extract floating-point numbers (that is, decimals) in the information: (-?\d*) \.? \d+
Extract any number in the information: (-?\d*) (\.\d+)?
Extract the Chinese string in the information: [\u4e00-\u9fa5]*
Extract a double-byte string (kanji) from the information: [^\x00-\xff]*

Friends who want to learn from the system can continue reading: Regular Expressions 30-minute introductory tutorials to further deepen the understanding of regular expressions.

The above is the regular expression of the mobile phone verification of all the content, we can extrapolate, mastery, hope for everyone's learning help, but also hope that we support cloud habitat community.

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.