Home Web Front-end JS Tutorial How to use regular expressions to match phone numbers and email addresses

How to use regular expressions to match phone numbers and email addresses

Jan 08, 2018 am 10:05 AM
match Phone number

This time I will show you how to use regular expressions to match phone numbers, mobile numbers, and email addresses. How to use regular expressions to match phone numbers, mobile numbers, and email addresses? What are the precautions for using regular expressions to match phone numbers, mobile phone numbers and email addresses? The following is a practical case, let’s take a look.

Match all url addresses and link content

Copy the code The code is as follows:

$str = "<a href=&#39;http://www.baidu.com&#39; target=&#39;_blank&#39;>百度</a>http://www<a href=&#39;http://www.sina.com&#39; target=&#39;_blank&#39;>新浪</a>kod"; 
preg_match_all("/<a href=([\"\&#39;])(http:\/\/([\w\d\.])+)[^>]*>(.*?)<\/a>/i", $str, $matches); 
echo "<pre class="brush:php;toolbar:false">"; 
var_dump($matches[2]); 
echo "<br />"; 
var_dump($matches[4]);
Copy after login

Match the email

Copy the code The code is as follows:

$emails = "wangzhanu@126.comha12wangzhanu@163.com"; 
preg_match_all("/([a-z0-9_\-\.]+)@(([a-z0-9]+[_\-]?)\.)+[a-z]{2,3}/i", $emails, $matches); 
var_dump($matches[0]);
Copy after login

Match mobile phone and phone number

Copy the code code as follows:

$tel = "13911112222sf010-44444442dfg18811112222"; 
preg_match_all("/1[3,5,8]{1}[0-9]{1}[0-9]{8}|0[0-9]{2,3}-[0-9]{7,8}(-[0-9]{1,4})?/", $tel, $matches); 
var_dump($matches);
Copy after login


I believe you have mastered it after reading these cases For more exciting methods, please pay attention to php Chinese websiteOther related articles!

Related reading:

How to use the template of the WeChat applet

How to use jquery's ajax to asynchronously submit form data

What is the order in which JS code is executed?

The above is the detailed content of How to use regular expressions to match phone numbers and email addresses. For more information, please follow other related articles on the PHP Chinese website!

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

Video Face Swap

Video Face Swap

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

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)

How to use Xiaohongshu account to find users? Can I find my mobile phone number? How to use Xiaohongshu account to find users? Can I find my mobile phone number? Mar 22, 2024 am 08:40 AM

With the rapid development of social media, Xiaohongshu has become one of the most popular social platforms. Users can create a Xiaohongshu account to show their personal identity and communicate and interact with other users. If you need to find a user’s Xiaohongshu number, you can follow these simple steps. 1. How to use Xiaohongshu account to find users? 1. Open the Xiaohongshu APP, click the &quot;Discover&quot; button in the lower right corner, and then select the &quot;Notes&quot; option. 2. In the note list, find the note posted by the user you want to find. Click to enter the note details page. 3. On the note details page, click the &quot;Follow&quot; button below the user's avatar to enter the user's personal homepage. 4. In the upper right corner of the user's personal homepage, click the three-dot button and select &quot;Personal Information&quot;

How to set up if WeChat does not allow adding by mobile phone number How to set up if WeChat does not allow adding by mobile phone number Mar 12, 2024 pm 05:04 PM

How to set up WeChat to disallow adding via mobile phone number? In WeChat APP, you can disallow adding WeChat via mobile phone number, but most users don’t know how to set it up to not allow WeChat to be added via mobile phone number. Next is WeChat brought by the editor to users It is not allowed to add setting method tutorials through mobile phone numbers. Interested users can come and take a look! Tutorial on how to use WeChat. How to set up WeChat when adding a mobile phone number is not allowed. 1. First open the WeChat APP, enter the main page, click [Me] in the lower right corner to enter, and select the [Settings] function; 2. Then enter the setting function page and find [Friend Permissions] ] Service function; 3. Then on the friend permissions interface, slide the button behind [Verification is required when adding me as a friend]; 4. Finally, on the page shown below, slide [Mobile Phone Number]

What does the +86 in front of a mobile phone number mean? What does the +86 in front of a mobile phone number mean? Jan 12, 2021 pm 02:17 PM

The +86 in front of the mobile phone number refers to China's international dialing code. When dialing a domestic mobile phone in China, adding "+86" is the same as not adding it; and the international telephone area code is assigned by the International Telecommunications Union according to the "E.164" standard. Country codes; all numbers are prefix numbers, which means these numbers are used to "dial" the destination country.

How to change the mobile phone number of Xiaohongshu account? Will there be any impact if I change my mobile phone number? How to change the mobile phone number of Xiaohongshu account? Will there be any impact if I change my mobile phone number? Mar 22, 2024 am 08:11 AM

In the digital age, Xiaohongshu has become a platform for many people to share their lives and discover good things. Over time, we may need to change the mobile phone number on the account. So, how to change Xiaohongshu’s mobile phone number? 1. How to change the mobile phone number of Xiaohongshu account? 1. Log in to your Xiaohongshu account and enter the “My” page. 2. Click &quot;...&quot; in the upper right corner and select &quot;Settings&quot;. 3. On the settings page, find the &quot;Account and Security&quot; option and click to enter. 4. On the Account and Security page, find the &quot;Mobile Phone Number&quot; option and click to enter. 5. At this time, the page will display the current mobile phone number, click &quot;Change Mobile Number&quot;. 6. Enter the new mobile phone number, receive the verification code, and fill it out. 7. Set a new password to ensure account security. 8. After completing the above steps,

Practical Guide to Regular Expressions in Go: How to Match Hexadecimal Color Codes Practical Guide to Regular Expressions in Go: How to Match Hexadecimal Color Codes Jul 13, 2023 am 10:46 AM

Go Language Regular Expressions Practical Guide: How to Match Hexadecimal Color Codes Introduction: Regular expressions are a powerful and flexible tool for pattern matching and finding strings. In Go language, we can use the built-in regular expression package regexp to implement these operations. This article will introduce how to use regular expressions to match hexadecimal color codes in Go language. Importing the regular expression package First, we need to import the regular expression package regexp of the Go language. You can add the following import statement at the beginning of the code: i

What should I do if my railway 12306 mobile phone number has been changed and cannot be verified? What should I do if my railway 12306 mobile phone number has been changed and cannot be verified? Feb 28, 2024 am 09:00 AM

In recent years, the various certification rules of Railway 12306 have been revised to make them more standardized. In the past, when you could buy tickets through other people's mobile phone numbers or old mobile phone numbers, now when buying tickets, you will be prompted for unauthenticated operations, which affects users' travel. So how to change the mobile phone number in 12306? This tutorial guide will bring you a detailed guide introduction, hoping to help everyone in need. Then the first choice is to click on the modify mobile phone number function when you have logged in to 12306app, then enter the modification page, click to bind a new mobile phone number, use the new mobile phone number to send a text message, then enter the text message editing page, follow the prompts to send the edit Please fill in the verification code received and enter it into 12306app to complete the modification.

How to register two B-site numbers with one mobile phone number? How does Station B unbind its mobile phone? How to register two B-site numbers with one mobile phone number? How does Station B unbind its mobile phone? Mar 21, 2024 pm 10:10 PM

Bilibili (Bilibili), as a video sharing website very popular among Chinese young people, has attracted a large number of users. Some users hope to have two Bilibili accounts so that they can be managed and used separately. So, how to register two B-site numbers with one mobile phone number? This article will focus on this issue and how to unbind the mobile phone. 1. How to register two B-site numbers with one mobile phone number? 1. Register a new account: First, open the Bilibili App on your mobile phone or log in to the official website, click the &quot;Register&quot; button, and select the registration method. You can use your mobile phone number, email or third-party account (such as WeChat, QQ, etc.) to register. 2. When registering an account, please fill in the necessary information according to the system prompts, including mobile phone number, verification code, and set password. Be sure to use different accounts

Enter your mobile phone number to check the full list of express delivery entrance URLs with one click Enter your mobile phone number to check the full list of express delivery entrance URLs with one click Feb 14, 2024 pm 11:33 PM

Express delivery is indispensable in today's life. Many users basically need to receive express delivery every day. Some users are curious about the URLs of the express delivery portals where they can enter their mobile phone number and check with just one click. Let’s take a look at the list of URLs brought by the editor. Enter your mobile phone number to check the complete list of express delivery entrance URLs with one click: National express delivery URL: https://www.ip138.com/ems/1, Express network: https://www.ickd.cn/2, Aicha Express : https://www.ickd.cn/3. Postal service: https://www.ems.com.cn/4. JD Logistics: https://www.jdl.com/5. STO Express: h

See all articles