Home > Backend Development > PHP Tutorial > PHP regular expression for matching phone numbers (supports location, live broadcast number, extension number)

PHP regular expression for matching phone numbers (supports location, live broadcast number, extension number)

WBOY
Release: 2016-07-25 08:58:25
Original
1194 people have browsed it
This article introduces an example of a regular expression for phone number matching in PHP. Friends in need can refer to it.

Regular expression example for phone number allocation:

<?php
/**
* 匹配电话号码的正则实例
* edit bbs.it-home.org
*/
$preg = '/(^0?1[2,3,5,6,8,9]\d{9}$)|(^(\d{3,4})-(\d{7,8})$)|(^(\d{7,8})$)|(^(\d{3,4})-(\d{7,8})-(\d{1,4})$)|(^(\d{7,8})-(\d{1,4})$)/';  
$b = '13345678901';  
$b = '013215245245';  
$b = '1234-12345678-1234';  
if(preg_match($preg, $b)){  
    echo "匹配到了";  
}else{  
    echo "没有匹配到";  
}  
?>
Copy after login

[2,3,5,6,8,9] Only these types of mobile phone numbers are provided: 12...,13...,15...,16...,18...,19.... Just add what's not enough and delete what's redundant. Perfectly supports various mobile phone numbers (supports mobile phone numbers containing 0 such as: 013545454875) and landline numbers.



source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template