search
Homephp教程PHP源码php中固定电话号码和手机号码正则表达式验证

     现在我们来总结一下关于php中固定电话号码和手机号码正则表达式验证,本实现可以验证目前所有中国座机与移动电话号码,有需要的朋友可参考一下。

086-区号-号码-分机
^086-[1-9][0-9]{1,4}-[1-9][0-9]{4,7}-[0-9]{3,4}$

2G的手机号差不多都是13开头

代码如下    复制代码    

$mobilephone=trim($_POST["smMobilePhone"]); 
//手机号码的正则验证 
if(preg_match("/^13[0-9]{1}[0-9]{8}$|15[0189]{1}[0-9]{8}$|189[0-9]{8}$/",$mobilephone)){ 
//验证通过 
}else{ 
//手机号码格式不对 
}

3G的号以150、151、158、159开头,还有就是189开头,所以代码如下。

代码如下    复制代码    

<?php
$mobilephone="18000000000";
if(preg_match("/^13[0-9]{1}[0-9]{8}$|15[0189]{1}[0-9]{8}$|189[0-9]{8}$/",$mobilephone)){ 
echo &#39;验证通过&#39;; 

}else{ 
echo &#39;手机号码格式不对&#39;; 

}

注意

故先要整清楚现在已经开放了多少个号码段,国家号码段分配如下:
移动:134、135、136、137、138、139、150、151、157(TD)、158、159、187、188

联通:130、131、132、152、155、156、185、186

电信:133、153、180、189、(1349卫通)

加上js处理

JScript code

代码如下    复制代码    

<script type="text/javascript">
var patter = /^1(5[0-35-9]|8[06789]|3[0-9]|47)d{8}$/;
/**
* 匹配固定电话 (区号-)+号码 区号可以不写,-也可以不写 匹配大部分固话,但不包括4位以上的区号地区的电话
*/
var patter = /^(0(10|21|22|23|[1-9][0-9]{2})(-|))?[0-9]{7,8}$/
</script>

/^13d{9}$/gi手机号正则表达式

代码如下    复制代码    

public static bool IsValidMobileNo(string MobileNo)
{
const string regPattern = @"^(130|131|132|133|134|135|136|137|138|139)d{8}$";
return Regex.IsMatch(MobileNo, regPattern);
}

正则表达式--验证手机号码:13[0-9]{9}

实现手机号前带86或是+86的情况:^((+86)|(86))?(13)d{9}$

电话号码与手机号码同时验证:(^(d{3,4}-)?d{7,8})$|(13[0-9]{9})

提取信息中的中国手机号码:(86)*0*13d{9}

提取信息中的中国固定电话号码:((d{3,4})|d{3,4}-|s)?d{8}

提取信息中的中国电话号码(包括移动和固定电话):((d{3,4})|d{3,4}-|s)?d

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

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.