Check email integrity in php

Source: Internet
Author: User
& Lt ;? Phpif (eregi (^ [_. 0-9a-z-] + @ ([0-9a-z] [0-9a-z-] + .) + [a-z] $, $ email) {echo your e-mail through a preliminary check ;}? & Gt; & nbsp; in this sentence, an eregi function is applied, which is easy to understand. If you want to find a book, you can give an explanation: & nbsp; syntax: inte If (eregi ("^ [_. 0-9a-z-] + @ ([0-9a-z] [0-9a-z-] +.) + [a-z] $", $ email )){
Echo "your email has passed the preliminary check ";
}
?>
In this sentence, an eregi function is first applied, which is quite understandable. If you look for a book, you can give an explanation:
Syntax: int ereg (string pattern, string, array [regs]);
Returned value: integer/array
This function uses the pattern rule to parse and compare strings.
The value returned from the comparison result is placed in the array parameter regs, the regs [0] content is the original string, regs [1] is the first regular string, regs [2] is the second regular string, and so on. If the regs parameter is omitted, only comparison is performed. if it is found, the return value is true.

What I don't quite understand is the previous regular expression: ^ [_. 0-9a-z-] + @ ([0-9a-z] [0-9a-z-] +.) + [a-z] $
In this regular expression, "+" indicates that one or more strings appear consecutively. "^" indicates that the next string must start, "$" indicates that the previous string must appear at the end;
"." That is, ".", here "is an escape character;" "indicates that the previous string can appear two or three times in a row. "()" Indicates that the contained content must appear in the target object at the same time. "[_. "0-9a-z-]" indicates that "_",". ","-", any character in the number range from a to z, from 0 to 9;
In this way, the regular expression can be translated as follows:
"The following characters must start with (^)", "must be included in "_",". ","-", letters from a to z, numbers from 0 to 9 ([_. 0-9a-z-]) "," the preceding character must appear at least once (+) ", @," this string starts with a character that contains a letter in the range from a to z and a number in the range from 0 to 9, followed by at least one character in the "-", any letter from a to z, any number from 0 to 9, and finally in. end ([0-9a-z] [0-9a-z-] + .)) "," the preceding character appears at least once (+) "," the letter from a to z appears 2-3 times, and ends with it ([a-z] $ )"
It's complicated, right? that's why people use regular expressions.

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.