Regular expression verification of fixed phone number and mobile number in PHP

Source: Internet
Author: User

086-area code-number-Ext
^086-[1-9][0-9]{1,4}-[1-9][0-9]{4,7}-[0-9]{3,4}$

2G's cell phone number is almost all 13.

The code is as follows Copy Code


$mobilephone =trim ($_post["Smmobilephone"]);
Regular verification of mobile phone number
if (Preg_match ("/^13[0-9]{1}[0-9]{8}$|15[0189]{1}[0-9]{8}$|189[0-9]{8}$/", $mobilephone)) {
Validation through

}else{
Phone number is not in the right format

}

The 3G number starts with 150, 151, 158, 159, and 189, so the code is as follows.

The code is as follows Copy Code

<?php

$mobilephone = "18000000000";
if (Preg_match ("/^13[0-9]{1}[0-9]{8}$|15[0189]{1}[0-9]{8}$|189[0-9]{8}$/", $mobilephone)) {
echo ' Verify through ';

}else{
Echo ' Phone number format is not correct ';

}


Attention

Therefore, we have to make clear the number of numbers which have been opened now, and the number of the country is divided into the following sections:

Mobile: 134, 135, 136, 137, 138, 139, 150, 151, 157 (TD), 158, 159, 187, 188

Unicom: 130, 131, 132, 152, 155, 156, 185, 186

Telecommunications: 133, 153, 180, 189, (1349 health)

Plus JS processing

JScript Code

The code is as follows Copy Code

<script type= "Text/javascript" >
var patter =/^1 (5[0-35-9]|8[06789]|3[0-9]|47) d{8}$/;
/**
* Matching fixed telephone (area code-) + number code can not write,-or can not write matching most of the landline, but not including more than 4 area code areas of the phone
*/
var patter =/^ (0 (10|21|22|23|[ 1-9][0-9]{2}) (-|))? [0-9] {7,8}$/
</script>


/^13d{9}$/gi cell phone number Regular expression

The code is as follows Copy Code

public static bool Isvalidmobileno (string Mobileno)

{

Const string Regpattern = @ "^ (130|131|132|133|134|135|136|137|138|139) d{8}$";

Return Regex.IsMatch (Mobileno, Regpattern);

}

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})

China Mobile phone number to extract information: (*0*13D{9)

Extract Chinese fixed phone number in information: ((d{3,4}) |d{3,4}-|s)? D{8}

Extract Chinese phone numbers in information (including mobile and fixed-line):((d{3,4}) |d{3,4}-|s)? d

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.