PHP email mailbox regular_PHP tutorial

WBOY
Release: 2016-07-21 15:48:58
Original
863 people have browsed it

1. Verify email:

Copy code The code is as follows:

1. < ?php
2. 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)){
3. echo “Your email address is correct!";}
4. else{
5. echo "Please try again!";
6. }
7. ?>

The format of the international domain name is as follows:
The domain name is composed of any combination of specific character sets, English letters, numbers and "-" (i.e. hyphens or minus signs) in various countries, but it cannot contain "-" at the beginning or at the end. "-" cannot appear continuously. Letters in domain names are not case-sensitive. The domain name can be up to 60 bytes long (including suffixes .com, .net, .org, etc.).
/^[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 Formula;
^ Match start
$ Match end
[a-z] E-Mail prefix must start with an English letter
([a-z0-9]*[-_]?[a- z0-9]+)* matches _a_2, aaa11, _1_a_2, but does not match a1_, aaff_33a_, a__aa. If it is a null character, it will also match. * means 0 or more.
* represents 0 or more previous characters.
[a-z0-9]* matches 0 or more English letters or numbers
[-_]? matches 0 or 1 "- ", because "-" cannot appear continuously
[a-z0-9]+ matches one or more English letters or numbers, because "-" cannot be the end
@ There must be @
([a-z0-9]*[-_]?[a-z0-9]+)+ see above ([a-z0-9]*[-_]?[a-z0-9]+) *Explanation, but it cannot be empty, + means one or more.
[.] Treat special characters (.) as ordinary characters
[a-z]{2,3} matches 2 to 3 English letters, usually com or net, etc.
([.][ a-z]{2})? Match 0 or 1 [.][a-z]{2} (such as .cn, etc.) I don’t know if the last part of .com.cn is usually two digits. If not, please Modify {2} to {starting word count, ending word count}
Perfect E-Mail regular expression, with detailed explanation, please help test it! 2. Extract email from the string:
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 If I am not from Mivi, I will open an iid mailing list: fuyongjie@163.com and hh@qq.com;, fuyongjie.100@yahoo.com, fu-1999@sina.com";
$emailArr = getEmail($emailstr);
echo "
"; <br>print_r($emailArr); <br>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: No. The regular expression in 2 no longer contains the first ^ and $;

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/319666.htmlTechArticle1. Verify email: Copy the code as follows: 1. ?php 2. 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)){ 3. e...
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!