Home php教程 PHP源码 PHP常用正则(手机号、座机、邮箱、身份证及手机号截取)

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

Jun 08, 2016 pm 05:22 PM
match pattern quot

主要分享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);

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

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)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

php提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决 php提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决 Jun 13, 2016 am 10:23 AM

php提交表单通过后,弹出的对话框怎样在当前页弹出php提交表单通过后,弹出的对话框怎样在当前页弹出而不是在空白页弹出?想实现这样的效果:而不是空白页弹出:------解决方案--------------------如果你的验证用PHP在后端,那么就用Ajax;仅供参考:HTML code

Using Pattern.compile method in Java Using Pattern.compile method in Java Feb 18, 2024 pm 09:04 PM

Usage of Pattern.compile function in Java The Pattern.compile function in Java is a method used to compile regular expressions. Regular expression is a powerful string matching and processing tool that can be used to find, replace, verify strings and other operations. The Pattern.compile function allows us to compile a string pattern into a Pattern object, which can then be used to perform a series of string operations. Pattern.compi

PatternSyntaxException class in Java regular expressions PatternSyntaxException class in Java regular expressions Sep 11, 2023 pm 07:37 PM

The PatternSyntaxException class represents an unchecked exception thrown when a syntax error occurs in a regular expression string. This class contains three main methods namely - getDescription() - returns the description of the error. getIndex() - Returns the error index. getPattern() - Returns the regular expression pattern in which the error occurred. getMessage() - Returns the complete message containing the error, the index, the regular expression pattern in which the error occurred, and the error in the indicated pattern. Example Real-time demonstration importjava.util.Scanner;importjava.util.regex.Matcher;i

Match matching method in java Match matching method in java Apr 28, 2023 pm 10:31 PM

Note that match is used for matching operations, and its return value is of boolean type. Through match, you can simply verify whether a certain element exists in the list. Example // Verify whether there is a string in the list starting with a, and match the first one, that is, return truebooleananyStartsWithA=stringCollection.stream().anyMatch((s)->s.startsWith("a"));System.out .println(anyStartsWithA);//true//Verify whether the string in the list

How to use regular expressions to match strings in Java? How to use regular expressions to match strings in Java? Apr 19, 2023 pm 02:37 PM

Concept 1. Various Match operations can be used to determine whether a given Predicate meets the elements of a Stream. 2. Match operation is a terminal operation and returns a Boolean value. Instance booleananyStartsWithA=stringCollection.stream().anyMatch((s)->s.startsWith("a"));System.out.println(anyStartsWithA);//truebooleanallStartsWithA=stringCollection.stream().

How to use java Match How to use java Match Apr 18, 2023 pm 01:55 PM

Concept 1. Various Match operations can be used to determine whether a given Predicate meets the elements of a Stream. 2. Match operation is a terminal operation and returns a Boolean value. Instance booleananyStartsWithA=stringCollection.stream().anyMatch((s)->s.startsWith("a"));System.out.println(anyStartsWithA);//truebooleanallStartsWithA=stringCollection.stream().

How to use Pattern function in Java for pattern matching How to use Pattern function in Java for pattern matching Jun 26, 2023 pm 02:55 PM

In Java, the Pattern function is a very powerful and flexible tool that helps developers perform precise pattern matching in text. In this article, we will introduce how to use the Pattern function for pattern matching. The Pattern function is part of the Java.util.regex package, which allows developers to define and parse regular expressions. Regular expressions are a powerful tool for matching and manipulating text. It can be used to check the number and order of occurrences of letters, numbers, special characters, etc.

不用数据库来实现用户的简单的下载,代码如下,但是却不能下载,请高手找下原因,文件路劲什么的没有关问题 不用数据库来实现用户的简单的下载,代码如下,但是却不能下载,请高手找下原因,文件路劲什么的没有关问题 Jun 13, 2016 am 10:15 AM

不用数据库来实现用户的简单的下载,代码如下,但是却不能下载,请高手找下原因,文件路劲什么的没问题。

See all articles