Php verifies regular expression of mobile phone number and phone number

Source: Internet
Author: User
Tags regular expression
The code is as follows: Copy code
Function funcphone ($ str) // call number regular expression test
{
Return (preg_match ("/^ (d {3}) | (d {3 }-))? (0d {2, 3}) | 0d {2, 3 }-)? [1-9] d {6, 8} $/", $ str ))? True: false;

// Usage

The code is as follows: Copy code
If (funcphone ('2017-100 '))
{
Echo 'correct phone number ';
}
Else
{
Echo 'Sorry, the phone number you entered is incorrect ';
}
 

 

The code is as follows: Copy code

Function funcmtel ($ str) // phone number regular expression test
{
Return (preg_match ("/(? : 13d {1} | 15 [03689]) d {8} $/", $ str ))? True: false;
}

// Mobile phone number verification application

If (funcmtel ('20140901 '))
{
Echo 'The phone number you entered is correct ';
}
Else
{
Echo 'Enter the valid mobile phone number of China Mobile or the linked mobile phone number ';
}

// We separated the phone number verification from the phone number verification. Now we need to verify both the phone number and the phone number at the same time.

The code is as follows: Copy code
If (functmtel ('000000') | funcphone ('2017-66661 '))
{
Echo 'you can continue the operation! ';
}
Else
{
Echo 'only one phone number or mobile phone number is required ';
}

/*
This example provides an example to verify the mobile phone number and phone number (landline) separately.

This site original reprinted indicated from http://www.111cn.net/phper/php.html
*/

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.