Regular expression to match email address in php_PHP tutorial
An example of a regular expression for matching email addresses in PHP. The regular matching expression I commonly use when replacing email addresses: /^[a-z]([a-z0-9]*[-_]?[a-z0 -9]+)*@([a-z0-9]*[-_]?[a-z0-9]+)+[\.][a-z]{2,3}([\.][a-z ]{2})?$/i, the following is a detailed analysis for friends in need.
php example
The following uses PHP as an example:
代码如下 | 复制代码 |
< ?php if (ereg(“/^[a-z]([a-z0-9]*[-_.]?[a-z0-9]+)*@([a-z0-9]*[-_]?[a-z0-9]+)+[.][a-z]{2,3}([.][a-z]{2})?$/i; ”,$email)) { echo “Your email address is correct!”; } else { echo “Please try again!”; } ?> |
Description:
①/content/i forms a case-insensitive regular expression; ^ starts the match; $ ends the match.
②[a-z] E-Mail prefix must start with an English letter
③([a-z0-9]*[-_]?[a-z0-9]+)* matches _a_2, aaa11, _1_a_2, but does not match a1_, aaff_33a_, a__aa, if it is a null character , is also matched, * means 0 or more.
④* represents 0 or more preceding characters.
⑤[a-z0-9]* matches 0 or more English letters or numbers; [-_]? matches 0 or 1 "-", because "-" cannot appear continuously.
⑥[a-z0-9]+ matches 1 or more English letters or numbers, because "-" cannot be used as the end
⑦@ There must be someone @
⑧([a-z0-9]*[-_]?[a-z0-9]+)+ See above ([a-z0-9]*[-_]?[a-z0-9 ]+)* explanation, but it cannot be empty, + means one or more.
⑨[.] treats special characters (.) as ordinary characters; [a-z]{2,3} matches 2 to 3 English letters, usually com or net, etc.
⑩([.][a-z]{2})? Matches 0 or 1 [.][a-z]{2} (such as .cn, etc.) I don’t know if the last part of .com.cn is usually two bit, if not, please change {2} to {number of starting words, number of ending words}
js example
The code is as follows
|
Copy code
|
||||
<script><br> function Email(ee){<br> var emailreg = "^w+@w+.w+(.w+)*$";<br> <br>var rege = new RegExp(emailreg, 'g');<br> alert(rege.test(ee)); }</td> var ee1 = "12xwz@123e^rsrf6.csdfdfom.df";</tr> var ee2 = "12xwz@123ersrf6.csdfdfom.df";</table> Email(ee1); Email(ee2);<p align="left"> </script> 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 UndressAI-powered app for creating realistic nude photos ![]() AI Clothes RemoverOnline AI tool for removing clothes from photos. ![]() Undress AI ToolUndress images for free ![]() Clothoff.ioAI clothes remover ![]() AI Hentai GeneratorGenerate 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
4 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
How Long Does It Take To Beat Split Fiction?
3 weeks ago
By DDD
R.E.P.O. Save File Location: Where Is It & How to Protect It?
3 weeks ago
By DDD
![]() Hot Tools![]() Notepad++7.3.1Easy-to-use and free code editor ![]() SublimeText3 Chinese versionChinese version, very easy to use ![]() Zend Studio 13.0.1Powerful PHP integrated development environment ![]() Dreamweaver CS6Visual web development tools ![]() SublimeText3 Mac versionGod-level code editing software (SublimeText3) ![]() Hot Topics![]() The top ten virtual currency trading app platforms in 2025 are: 1. OKX; 2. Binance; 3. Gate.io; 4. Huobi Global; 5. Kraken; 6. Coinbase; 7. KuCoin; 8. Crypto.com; 9. Bitfinex; 10. MEXC Global. The ranking considers factors such as market share, user experience, security, transaction fees, etc., but is for reference only. ![]() OKX Ouyi is a leading cryptocurrency trading platform. This article will provide detailed steps to guide you on how to register an OKX Ouyi official website account. You will learn how to access the official website, choose the registration method, fill in the necessary information, and complete the registration process. The article also contains information about precautions, such as the importance of using real personal information and setting a strong password. ![]() A detailed introduction to the login operation of the Sesame Open Exchange web version, including login steps and password recovery process. It also provides solutions to common problems such as login failure, unable to open the page, and unable to receive verification codes to help you log in to the platform smoothly. ![]() Gateio Exchange app download channels for old versions, covering official, third-party application markets, forum communities and other channels. It also provides download precautions to help you easily obtain old versions and solve the problems of discomfort in using new versions or device compatibility. ![]() This guide provides detailed download and installation steps for the official Bitget Exchange app, suitable for Android and iOS systems. The guide integrates information from multiple authoritative sources, including the official website, the App Store, and Google Play, and emphasizes considerations during download and account management. Users can download the app from official channels, including app store, official website APK download and official website jump, and complete registration, identity verification and security settings. In addition, the guide covers frequently asked questions and considerations, such as ![]() Gate.io (Sesame Open Door) is the world's leading cryptocurrency trading platform. This article provides a complete tutorial on spot trading of Gate.io. The tutorial covers steps such as account registration and login, KYC certification, fiat currency and digital currency recharge, trading pair selection, limit/market transaction orders, and orders and transaction records viewing, helping you quickly get started on the Gate.io platform for cryptocurrency trading. Whether a beginner or a veteran, you can benefit from this tutorial and easily master the Gate.io trading skills. ![]() The login method of the Sesame Open Door Trading Platform is convenient. Users only need to visit their official website (please search for the domain name yourself), enter the registered email/mobile phone number and password to log in. The platform may enable security verification mechanisms such as 2FA to ensure account security. ![]() OKX trading platform, a digital asset trading platform trusted by global users. The platform provides a variety of digital asset trading services, including spot trading, futures trading, option trading, etc. ![]() |