Home > php教程 > php手册 > 分享一些常用的正则验证

分享一些常用的正则验证

WBOY
Release: 2016-06-07 11:42:48
Original
1182 people have browsed it

在日常的项目开发中。需要正则验证一些数据的合法性。这些正则也是平时自己收藏的。有些可能已经不太适用。但可以适当的修改一二就可以用了
//验证手机号<br> $match = '/^((13[0-9])|(15[^4,\\d])|(18[0,5-9]))[0-9]{8}$/';<br> <br> //验证座机<br> $match = '/^(0[0-9]{2,3}\-)?([2-9][0-9]{6,7})+(\-[0-9]{1,4})?$/';<br> <br> //验证身份证号15或18位<br> $match = '/(^\d{15}$)|(^\d{17}(\d|X|x)$)/';<br> <br> //Email验证<br> $match = '/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/';<br> <br> //将手机号中间转换为 * 号<br> $tel = 18612345678;<br> $pattern = '/(\d{3})\d{4}(\d{3})/';<br> $replacement = "\$1****\$2";<br> echo preg_replace($pattern,$replacement,$tel);

AD:真正免费,域名+虚机+企业邮箱=0元

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