1. Verify Email:
< PHP
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!";
}
Or
$str = ';
$isMatched = Preg_match ('/^\w[-\w.+]*@ (a-za-z0-9][-a-za-z0-9]+\.) +[a-za-z]{2,14}$/', $str, $matches);
Var_dump ($isMatched, $matches);
Regular expression matching email mailbox format:
Parsing:
//I constitutes a case-insensitive regular expression;
^ match start
$ match End
[A-z] e-mail prefix must be an English letter
([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 a match, * represents 0 or more. The
* represents 0 or more preceding characters.
[a-z0-9]* matches 0 or more English letters or numbers
[-_]? matches 0 or 1 "-" because "-" cannot appear consecutively
[a-z0-9]+ matches 1 or more 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 null, + represents one or more.
[\.] Converts special characters (.) As a normal character
[a-z]{2,3} matches 2 to 3 English letters, typically COM or net.
([\.] [A-z] {2})? Match 0 or 1 [\.] [A-z] {2} (such as. cn, etc.) do not know the general. Com.cn the last part is not all two digits, if not please modify {2} to {starting words, end words}
This is used to match the regular expression of the mailbox, or relatively strong, powerful, extensive, useful to the collection of friends. The
International Domain name format is as follows:
The domain name is composed of a particular character set, an English letter, a number, and a "-" (that is, a hyphen or a minus sign) of each country's text, but neither the beginning nor the end can contain a "-", "-" The letters in the domain name are not case-insensitive. The domain name can be up to 60 bytes (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; The
/content/I forms a case-insensitive regular expression;
^ match start
$ match End
[A-z] e-mail prefix must begin with an English letter
([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 a match, * represents 0 or more. The
* represents 0 or more preceding characters.
[a-z0-9]* matches 0 or more English letters or numbers
[-_]? match 0 or 1 "-" because "-" cannot appear consecutively
[a-z0-9]+ matches 1 or more English letters or numbers, because "-" cannot be the end
@ must have a @ br> ([a-z0-9]*[-_]?[ a-z0-9]+) + See above ([a-z0-9]*[-_]?[ a-z0-9]+) * explanation, but cannot be null, + represents one or more.
[\.] Converts special characters (.) As a normal character
[a-z]{2,3} matches 2 to 3 English letters, typically COM or net.
([\.] [A-z] {2})? Match 0 or 1 [\.] [A-z] {2} (for example, CN, etc.) I don't know. com.cn the last part is not all two digits, if not please modify {2} to {start words, end words}
Perfect e-mail regular expression, with detailed explanation, please help test! 2. Extract the email from the string:
<?php
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 the M VI Place to open IID mailing list: fuyongjie@163.com and hh@qq.com;. ;;, fuyongjie.100@yahoo.com,fu-1999@sina.com ";
$EMAILARR = Getemail ($EMAILSTR);
echo "<pre>";
Print_r ($EMAILARR);
echo "</pre>";
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: In the 2nd, there are no 1th ^ and $;