An explanation of commonly used email verification statements in PHP_PHP Tutorial

WBOY
Release: 2016-07-15 13:22:53
Original
888 people have browsed it

I believe that anyone who has studied PHP well should know the following statement for email verification, but not many can really understand it:
if (eregi("^ [_.0-9a-z-]+@([0-9a-z][0-9a-z-]+.)+[a-z]{2,3}$",$email)) {
echo "Your E-Mail passed the preliminary check";
}
?>
In this sentence, first of all, an eregi function is applied, which 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 follows the rules of pattern To parse and compare 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 regular expression: ^[_.0-9a-z-]+@([0-9a-z][0-9a-z-]+. )+[a-z]{2,3}$
In this regular expression, "+" means that the previous string appears one or more consecutively; "^" means that the next string must appear at the beginning, "$" means that the previous string must appear at the end;
"." is also ".", where "" is the escape character; "{2,3}" means that the previous string can appear continuously 2- 3 times. "()" means that the contained 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 contained 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]{2,3}$)”
It’s complicated, right, and that’s why people use regular expressions.


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/446913.htmlTechArticleI believe that anyone who has studied PHP well should know the following statement for eamil verification, but it can really Not much can be understood: if (eregi("^[_.0-9a-z-]+@([0-9a-z][0-9a-z-]+.)+[a-z]{ 2,3}...
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