Home  >  Article  >  Backend Development  >  Regular expression example: Check email integrity in php_PHP tutorial

Regular expression example: Check email integrity in php_PHP tutorial

WBOY
WBOYOriginal
2016-07-20 11:04:20961browse

if (eregi("^[_.0-9a-z-]+@([0-9a-z][0-9a-z-]+.)+[a-z]$" ,$email)) {
echo "Your email passed the preliminary check";
}
?>
In this sentence, an eregi function is first applied. This function It's 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. regs[2] is The second regular string, 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]$
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 ".", where "" is the escape character; "" means that the previous string can appear 2-3 times in a row. "()" 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 (^)", "The characters 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. That’s why people use regular expressions.



www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/445213.htmlTechArticle?php if (eregi("^[_.0-9a-z-]+@([0- 9a-z][0-9a-z-]+.)+[a-z]$",$email)) { echo "Your E-Mail passed the preliminary check"; } ? In this sentence, the first is the application Got an eregi function, this function...
Statement:
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