Correct Method for verifying EMAIL addresses using PHP (1)

Source: Internet
Author: User

The Internet task engineering group (IETF) document, written by John Klensin, RFC 3696 "Application Technology check and name conversion" provides multiple real and valid EMAIL addresses, but unfortunately these addresses were rejected by most PHP validators, addresses Abc @ def@example.com, customer/department = shipping@example.com and! Def! Xyz % abc@example.com is valid, and below is a very popular regular expression given in the relevant literature, but it rejects all the e-mail addresses given above:

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

This regular expression can only contain underscores (_), hyphens (-), numbers, and uppercase/lowercase letters. Even if the uppercase and lowercase letters are converted before this, the system rejects the slash (/), equal sign (=), and exclamation point (!) characters that contain the slash (!) And percent sign (%. This expression also requires that the highest level of the domain component must contain at least two or three characters, so it also rejects valid fields, such as. museum.

Another popular regular expression is:

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

This regular expression also rejects the valid example address given in the previous paragraph. it elegantly solves the case of upper-case letters and does not return an error when the highest-level domain name has only two or three characters, however, it allows invalid domain names, such as example..com.

Listing 1 shows (

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.