Check email integrity in PHP _php

Source: Internet
Author: User
Keywords Completeness check string range one character
if (eregi ("^[_.0-9a-z-]+@" ([0-9a-z][0-9a-z-]+.) +[a-z]$ ", $email)) {
echo "Your e-mail through a preliminary check";
}
?>
In this sentence, the first is the application of a eregi function, this function is good understanding. If you look for a book, you can give an explanation:
Syntax: int ereg (string pattern, string string, array [regs]);
return value: Integer/array
This function parses string strings with the rule of pattern.
The value returned from the result is placed in the array parameter regs, Regs[0] content is the original string, string, Regs[1] is the first rule of the string, Regs[2] is the second rule of the string, and so on. If the parameter regs is omitted, it is simply a comparison, and the return value is true if found.

What is not well understood is the preceding regular expression: ^[_.0-9a-z-]+@ ([0-9a-z][0-9a-z-]+.) +[a-z]$
In this regular expression, "+" means that the preceding string has one or more occurrences; "^" means that the next string must appear at the beginning and "$" means that the previous string must appear at the end;
"." That is, ".", where "" is the escape character; "" indicates that the preceding string can occur 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, and numbers in the range from 0 to 9;
In this way, the regular expression can be translated like this:
"The following character must be at the beginning (^)", "the character must be contained in" _ ",". ","-", letters from A to Z range, numbers in the range from 0 to 9 ([_.0-9a-z-])," precedes this character at least once (+) ", @," The string starts with a character that is contained in a number from A to Z range, from 0 to 9, followed by at least one of the characters contained in "-", any letter from A to Z range, from 0 to 9 in any number, and finally ends with. ([0-9a-z][0-9a-z- ]+.) "," Before this character appears at least once (+) "," the letter from the A to the Z range appears 2-3 times and ends with it ([a-z]$) "
It's complicated, right, and that's why people use regular expressions.

  • Related Article

    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.