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 ![]() Video Face SwapSwap faces in any video effortlessly with our completely free AI face swap tool! ![]() Hot Article
Assassin's Creed Shadows: Seashell Riddle Solution
3 weeks ago
By DDD
What's New in Windows 11 KB5054979 & How to Fix Update Issues
2 weeks ago
By DDD
Where to find the Crane Control Keycard in Atomfall
3 weeks ago
By DDD
Assassin's Creed Shadows - How To Find The Blacksmith And Unlock Weapon And Armour Customisation
1 months ago
By DDD
Roblox: Dead Rails - How To Complete Every Challenge
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
CakePHP Tutorial
![]() ![]() ![]() The future of PHP will be achieved by adapting to new technology trends and introducing innovative features: 1) Adapting to cloud computing, containerization and microservice architectures, supporting Docker and Kubernetes; 2) introducing JIT compilers and enumeration types to improve performance and data processing efficiency; 3) Continuously optimize performance and promote best practices. ![]() PHP and Python each have their own advantages, and the choice should be based on project requirements. 1.PHP is suitable for web development, with simple syntax and high execution efficiency. 2. Python is suitable for data science and machine learning, with concise syntax and rich libraries. ![]() PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners. ![]() SQLLIMIT clause: Control the number of rows in query results. The LIMIT clause in SQL is used to limit the number of rows returned by the query. This is very useful when processing large data sets, paginated displays and test data, and can effectively improve query efficiency. Basic syntax of syntax: SELECTcolumn1,column2,...FROMtable_nameLIMITnumber_of_rows;number_of_rows: Specify the number of rows returned. Syntax with offset: SELECTcolumn1,column2,...FROMtable_nameLIMIToffset,number_of_rows;offset: Skip ![]() PHP remains important in modern web development, especially in content management and e-commerce platforms. 1) PHP has a rich ecosystem and strong framework support, such as Laravel and Symfony. 2) Performance optimization can be achieved through OPcache and Nginx. 3) PHP8.0 introduces JIT compiler to improve performance. 4) Cloud-native applications are deployed through Docker and Kubernetes to improve flexibility and scalability. ![]() PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7 ![]() The reasons why PHP is the preferred technology stack for many websites include its ease of use, strong community support, and widespread use. 1) Easy to learn and use, suitable for beginners. 2) Have a huge developer community and rich resources. 3) Widely used in WordPress, Drupal and other platforms. 4) Integrate tightly with web servers to simplify development deployment. ![]() PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers. ![]() |