Home > Backend Development > PHP Tutorial > The correct way to verify EMAIL address with PHP (1)_PHP tutorial

The correct way to verify EMAIL address with PHP (1)_PHP tutorial

WBOY
Release: 2016-07-15 13:24:38
Original
936 people have browsed it

The Internet Task Force Engineering Group (IETF) document RFC 3696 "Application Technical Review and Naming Transformation" written by John Klensin gives multiple real and valid EMAIL addresses, but unfortunately these addresses have been Rejected by most PHP validation programs, the addresses Abc@def@example.com, customer/department=shipping@example.com and !def!xyz%abc@example.com are all valid, as shown below in the relevant literature A very popular regular expression is given, but it rejects all EMAIL addresses given earlier:

^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,3})$
Copy after login

This regular expression only allows underscores (_) and hyphens (-), numbers and Uppercase and lowercase letters. Addresses containing slashes (/), equal signs (=), exclamation points (!), and percent signs (%) will be rejected even if the letters have been converted to uppercase and lowercase before this. This expression also requires that the top-level domain component be at least 2 or 3 characters, so valid domains such as .museum will also be rejected.

Another favorite regex is:

^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+.[a-zA-Z0-9-.]+$
Copy after login

This regex will also reject the valid example address given in the previous paragraph, and it elegantly solves the capital letter problem , and no error will be reported when the top-level domain name has only 2 or 3 characters, but it also allows invalid domain names, such as example..com.

Listing 1 shows an example from the PHP Dev Shed (

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/446749.htmlTechArticle Internet Task Engineering Group (IETF) document RFC 3696 "Application Technology Checks and Naming Transformations" written by John Klensin Multiple real and valid EMAIL addresses were given, but unfortunately this...
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template