PHP e-mail address regular expression implementation and detailed, e-mail address regular expression _php tutorial

Source: Internet
Author: User

PHP e-mail address regular expression implementation and detailed, e-mail address regular expression


This article not only to tell about the regular Tatsu and also about the composition of the mailbox is the use of a detailed explanation, there is a need to understand the friend can refer to, at the same time we also provide a variety of different mailbox verification examples.
Regular expression.


^[_.0-9a-z-]+@ ([0-9a-z][0-9a-z-]+.) +[a-z]{2,3}$

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; "{2,3}" means that the preceding string can appear consecutively 2-3 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]{2,3}$) "

Code to copy code as follows
function Is_valid_email ($email, $test _mx = False)
{
if (eregi ("^ ([_a-z0-9-]+) (. [ _a-z0-9-]+) *@ ([a-z0-9-]+) (. [ a-z0-9-]+) * (. [ a-z]{2,4}) [Wind_phpcode_0]quot;, $email))
if ($test _mx)
{
List ($username, $domain) = Split ("@", $email);
Return Getmxrr ($domain, $mxrecords);
}
Else
return true;
Else
return false;
}

A domain name is made up of any combination of specific character sets, English letters, numbers, and "-" (that is, hyphens or minus signs) of each country's characters, but neither the beginning nor the end can contain "-", "-" cannot appear continuously. The letters in the domain name are not case-sensitive. The domain name can be up to 60 bytes long (including suffix. com,. NET,. org, and so on).
/^[a-z] ([a-z0-9]*[-_]?[ a-z0-9]+) *@ ([a-z0-9]*[-_]?[ a-z0-9]+) +[.] [A-z] {2,3} ([.] [A-z] {2})? $/i;
/content/I forms a case-insensitive regular expression;
^ Match start

$ match End

[A-z] e-mail prefix must be an English letter beginning

([A-z0-9]*[-_]? [a-z0-9]+] * and _a_2, AAA11, _1_a_2 match, and A1_, Aaff_33a_, A__aa do not match, if it is a null character, is also matched, * represents 0 or more.

* Represents 0 or more of the preceding characters.

[a-z0-9]* matches 0 or more English letters or numbers

[-_]? Match 0 or 1 "-" because "-" cannot appear continuously

[a-z0-9]+ matches 1 or more English letters or numbers, because "-" cannot be the end

@ must have a @

([A-z0-9]*[-_]? [a-z0-9]+] + see above ([a-z0-9]*[-_]?[ a-z0-9]+) * explanation, but cannot be empty, + denotes one or more.

[.] The special character (.) As ordinary characters

[A-z] {2,3} matches 2 to 3 English letters, typically COM or net.

([.] [A-z] {2})? Match 0 or 1 [.] [A-z] {2} (e.g.. CN, etc.) I don't know the general. Com.cn the last part is not all two-bit, if not please modify {2} to {start Word, end Word}

Perfect e-mail regular expression, with detailed explanation, please help test it! 2. Extract the email from the string:

Code to copy code as follows
function Getemail ($STR) {
$pattern = "/([A-z0-9]*[-_.]? [a-z0-9]+] *@ ([a-z0-9]*[-_]?[ a-z0-9]+) +[.] [A-z] {2,3} ([.] [A-z] {2})? /I ";
Preg_match_all ($pattern, $str, $EMAILARR);
return $EMAILARR [0];
}
$emailstr = "9999@qq.com.cn I am not a http://www.hzhuti.com/nokia/5235/vi place to open the IID mailing list: fuyongjie@163.com and hh@qq.com;. ;;, fuyongjie.100@yahoo.com,fu-1999@sina.com ";
$EMAILARR = Getemail ($EMAILSTR);
echo "

";
Print_r ($EMAILARR);
echo "
";
?> print as follows:
Array
(
[0] =>9999@qq.com.cn
[1] =>fuyongjie@163.com
[2] =>hh@qq.com
[3] =>fuyongjie.100@yahoo.com
[4] =>fu-1999@sina.com
) 3. Comparison: The 2nd in the regular is not the 1th ^ and $;

See the example again

Code to copy code as follows
function Funcemail ($STR)//mailbox Regular expression
{
Return (Preg_match ('/^[_.0-9a-z-a-z-]+@ ([0-9a-z][0-9a-z-]+.) +[a-z]{2,4}$/', $str))? True:false;
}//Verification Method One

$str = "qbcd@126.com.cn";
Preg_match ("/^[0-9a-z]+@ ([0-9a-z]+) [.]) +[a-z]{2,3}$/", $str, $re);
Print_r ($re);//e-mail authentication two

if (eregi ("^[_.0-9a-z-]+@" ([0-9a-z][0-9a-z-]+.) +[a-z]{2,3}$ ", $email)) {
echo "Your e-mail through a preliminary check";
}//third type of mailbox authentication method

if (Ereg ("/^[a-z") ([A-z0-9]*[-_.]? [a-z0-9]+] *@ ([a-z0-9]*[-_]?[ a-z0-9]+) +[.] [A-z] {2,3} ([.] [A-z] {2})? $/i; ", $email)) {
echo "Your email address is correct!";}
else{
echo "Please try again!";
}

http://www.bkjia.com/PHPjc/1114477.html www.bkjia.com true http://www.bkjia.com/PHPjc/1114477.html techarticle PHP e-mail address regular expression implementation and detailed, e-mail address regular expression in this article not only to tell about the regular and also about the structure of the use of the mailbox is explained in detail, there are ...

  • 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.