Php verifies regular expression of mobile phone number and phone number

Source: Internet
Author: User
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
*/

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.