Latest mobile phone number regular expression (php version)

Source: Internet
Author: User
Latest mobile phone number regular expression (php version)
This article describes how to use regular expressions to verify the latest phone number segments, including 150, 158, 159, and 188. For more information, see.

Previously, programmer's house introduced some regular expressions used to verify mobile phone numbers. for example, php matches the regular expression of phone numbers (location, live video number, and extension number supported) regular expressions are commonly used in php (date phones, Chinese mailboxes, etc.). However, the mobile phone number is now added to the section 150,153,156,158,159,157,188,189 and so on. here we will add the relevant regular expressions. As follows:

Code example: string s = @ "^ (13 [0-9] | 15 [0 | 3 | 6 | 7 | 8 | 9] | 18 [8 | 9]) \ d {8} $ ";

Then add 180,147 and so on:

Code example: ^ (1 ([35] [0-9]) | (47) | [8] [0126789]) \ d {8} $

Modify the 183 and add the landline as follows:

Code example: Mobile phone: ^ (1 ([35] [0-9]) | (47) | [8] [01236789]) \ d {8} $ landline: ^ 0 \ d {2, 3 }(\-)? \ D {7, 8} $

The following describes two regular expressions used in php and java to verify the mobile phone number.

1, php version

Sample code:

2, java

Sample code:

Using System; using System. Collections. Generic; using System. Text; using System. Text. RegularExpressions; using System. Windows. Forms;

Namespace ConsoleApplication1 {class Program {static void Main (string [] args) {// string s = @ "^ (13 [0-9] | 15 [0 | 3 | 6 | 8 | 9]) \ d {8} $ ";

String s = @ "^ (13 [0-9] | 15 [0 | 3 | 6 | 7 | 8 | 9] | 18 [8 | 9]) \ d {8} $ "; while (true) {string input = Console. readLine (); if (Regex. isMatch (input, s) {MessageBox. show ("fully compliant! ");} Else {MessageBox. Show (" No! ");}}}}}

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.