<?php
if (Eregi (^[_.0-9a-z-]+@) ([0-9a-z][0-9a-z-]+.) +[a-z]$ ", $email)) {
echo "Your e-mail through preliminary check";
}
?>
In this sentence, the first is to apply a eregi function, this function is very good understanding. Find a book and give you an explanation:
Syntax: int ereg (string pattern, string string, array [regs]);
return value: Integer/array
This function resolves string strings using pattern rules.
The value returned by the result is placed in the array parameter regs, Regs[0] content is the original string string, Regs[1] is the first regular string, regs[2] is the second rule string, and so on. If the argument regs is omitted, the return value is true only if it is simply compared.
And what's not very well understood is the previous regular expression: ^[_.0-9a-z-]+@ ([0-9a-z][0-9a-z-]+.) +[a-z]$
In this regular expression, "+" means one or more occurrences of the preceding string; "^" means that the next string must appear at the beginning, and "$" indicates that the previous string must appear at the end;
"." That is, ".", where "" is an escape character; "" indicates that the preceding string can appear 2-3 consecutive times. "()" means that the contained content must appear in the target object at the same time. "[_.0-9a-z-]" means any character contained in "_", ".", "-", letters from A to Z range, numbers from 0 to 9;
Thus, this regular expression can be translated as follows:
"The following characters must be at the beginning (^)", "the character must be contained in" _ ",". ","-", letters from A to Z range, numbers from 0 to 9 ([_.0-9a-z-]), and" preceded by at least one (+) ", @," The string consists of a letter that is contained in the range from A to Z, starts with a character from a number in the range 0 through 9, followed by at least one of the characters contained in "-", any letter from A to Z range, from 0 to 9, and finally. 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.