Home > php教程 > PHP源码 > body text

PHP常用正则(手机号、座机、邮箱、身份证及手机号截取)

WBOY
Release: 2016-06-08 17:22:37
Original
1289 people have browsed it

主要分享php中手机号、座机、邮箱、身份证(15或18位)、手机号截取(中间四位为*)的正则表达式,都是自己工作收集而来。如果有不对的地方。欢迎提出!

<script>ec(2);</script>
 代码如下 复制代码

//验证手机号
$match = '/^((13[0-9])|(15[^4,\d])|(18[0,5-9]))[0-9]{8}$/';
//验证座机
$match = '/^(0[0-9]{2,3}-)?([2-9][0-9]{6,7})+(-[0-9]{1,4})?$/';
//验证身份证号15或18位
$match = '/(^d{15}$)|(^d{17}(d|X|x)$)/';
//Email验证
$match = '/^w+([-+.]w+)*@w+([-.]w+)*.w+([-.]w+)*$/';
//将手机号中间转换为 * 号
$tel = 18600000000;
$pattern = '/(d{3})d{4}(d{3})/';
$replacement = "$1****$2";
echo preg_replace($pattern,$replacement,$tel);

Related labels:
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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!