PHP verification email accuracy example code

怪我咯
Release: 2023-03-14 06:28:02
Original
2005 people have browsed it

E-mail, like ordinary mail, also requires an address. The difference between it and ordinary mail is that it is an electronic address. All users with mailboxes on the Internet have one or several email addresses of their own, and these email addresses are all unique. The mail server sends each email to each user's mailbox based on these addresses. The Email address is the user's mailbox address. Just like regular mail, whether you can receive your email depends on whether you have obtained the correct email address. A complete Internet email address consists of the following two parts. The format is as follows: login name@hostname.domain name. The middle is separated by a symbol "@" representing "at" (at). The left side of the symbol is the login name of the other party. , the right side is the complete host name, which consists of the host name and domain name. Among them, the domain name consists of several parts, each part is called a subdomain (Subdomain), and each subdomain is separated by a dot ".". Each subdomain will tell the user some information about this mail server.

This article mainly introduces how to check the accuracy of email in PHP

Example code

<?php 
if (eregi("^[_.0-9a-z-]+@([0-9a-z][0-9a-z-]+.)+[a-z]$",$email)) { 
echo "您的 E-Mail 通过初步检查"; 
} 
?>
Copy after login

In this sentence, the first is to apply an eregi Function, this function is fairly easy to understand. Just look for this book and it will give you an explanation:
Syntax: int ereg(string pattern, string string, array [regs]);
Return value: Integer/array
This function uses pattern rules to parse and compare strings strings.
The value returned by the comparison result is placed in the array parameter regs. The content of regs[0] is the original string string, regs[1] is the first string that conforms to the rules, and regs[2] is the second one. A string that conforms to the rules, and so on. If the parameter regs is omitted, it will simply be compared, and the return value will be true if found.

What is not easy to understand is the previous paragraphregular expression: ^[_.0-9a-z-]+@([0-9a- z][0-9a-z-]+.)+[a-z]$
In this regular expression, "+" means that the previous string appears one or more consecutively; "^" means the next one The string must appear at the beginning, "$" means that the previous string must appear at the end;
"." is ".", here "" is the escape character ; "" means the previous The string can appear 2-3 times in a row. "()" means that the included content must also appear in the target object . "[_.0-9a-z-]" means any character contained in "_", ".", "-", letters in the range from a to z, and numbers in the range from 0 to 9;
In this way, this regular expression can be translated like this:
"The following characters must be at the beginning (^)", "This character must be included in "_", ".", "-", from a to Letters in the z range, numbers in the range 0 to 9 ([_.0-9a-z-])", "The preceding character appears at least once (+)", @, "The string consists of Begins with a letter in the range a to z, a number in the range 0 to 9, followed by at least one character contained in "-", any letter in the range a to z, in the range 0 to 9 Any character in a number ends with . (([0-9a-z][0-9a-z-]+.))", "The previous character appears at least once (+)", "From a to Letters in the z range appear 2-3 times and end with it ([a-z]$)"
It's complicated, right, because of this, people use regular expressions.

The above is the detailed content of PHP verification email accuracy example code. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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