Check email Integrity in PHP

Source: Internet
Author: User
Tags array end expression range regular expression return string

<?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 also good to understand. Find a book, and I'll give you an explanation.: 
Syntax: int ereg (string pattern, string string, array [regs]); 
return value: Integer/array  
This function is P Attern the rule to parse the string.  
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.



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.