search
Homephp教程php手册php 手机号码正则表达试程序代码

php 手机号码正则表达试程序代码

Jun 13, 2016 am 11:34 AM
functionphpstrcodephone numberregularprogramsurface

  代码如下

  function funcMtel($str)//手机号码正则表达试

  {

  return (preg_match("/(?:13d{1}|15[03689])d{8}$/",$str))?true:false;

  }

  测试

  18678785887

  返回为

  false

  原因分析,查看了发现上面正则只能验证以13,15开头的,自然18开头的是不可以用的

  修改后

  代码如下

  function funcMtel($str)//手机号码正则表达试

  {

  return (preg_match("/(?:1[3|4|5|8]d{1}|15[03689])d{8}$/",$str))?true:false;

  }

  测试

  18678785887

  返回为

  true

  这样就成功了,

  总结经验:

  像手机号这类都会不断更新号码段了,我们在写函数时把它写成公共函数,这样就可以解决这个问题了。

Statement
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment