Php verification mobile phone number

Source: Internet
Author: User
Tags php code

// Php code

$ Mobilephone = trim ($ _ post ["smmobilephone"]);
// Regular verification of mobile phone numbers
If (preg_match ("/^ 13 [0-9] {1} [0-9] {8} $ | 15 [0189] {1} [0-9] {8} $ | 189 [0-9] {8} $ /", $ mobilephone )){
// Verification passed
       
} Else {
// Incorrect mobile phone number format
       
}  

// This is only an inaccurate verification. It can only be roughly verified to a specific range, so the focus is still on the future.

// Mobile phone number verification 2

$ Tel = "15905789568 ";
$ AB = preg_match ("/^ 13 [0-9] {1} [0-9] {8} $ | 15 [0189] {1} [0-9] {8} $ | 189 [0-9] {8} $ /", $ tel );
 
/*
Note:
^ Indicates the start of this character (metacharacters)
$ Indicates the end of a character (metacharacter)
13 is a common character
[0-9] indicates a 0-9 number.
{9} indicates 9 matches
The following number. If it starts with 13 and has 9 digits in the middle and ends with it, it meets the conditions.
*/
 
If ($ AB)
 {
Echo "the phone number is correct ";
 
 }
Else
Echo "it's not a mobile phone number. Enter it in disorder !!!! ";

// Another mobile phone number verification program

Function checkmobile ($ str)
 {
$ Pattern = "/^ (13 | 15) d {9} $ /";
If (preg_match ($ pattern, $ str ))
     {
Return true;
     }
Else
     {
Return false;
     }
 }

// Call a function
$ Str = checkmobile ("15800000001 ");
If ($ str)
 {
Echo ("compliant with mobile phone number Standards ");
 }
Else
 {
Echo ("non-compliant with mobile phone number Standards ");
 }

?>

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.