Php checks the email function ). A previously written PHP form email sending program that uses the following method to verify that the email address format is correct: the code below copies the code eregi (^ [_ a-z0-9-] + (. [_ a PHP form email sending program previously written by a-z0, which uses the following method to verify that the email address format is correct:
The code is as follows:
Eregi ("^ [_ a-z0-9-] + (. [_ a-z0-9-] +) * @ [a-z0-9 _-] +. [a-z0-9 _-] +. * ", $ email)
Later, it was found that the email address similar to writing. by mistake can also pass verification, such as user @ 126 and com. After checking, it is found that it only verifies the user name, so I found a tutorial on the internet. The example is as follows:
The code is as follows:
Eregi ('^ [_ a-z0-9-] + (. [_ a-z0-9-] +) * @ [a-z0-9-] + (. [a-z0-9-] +) * $ ', $ email)
After checking, it is found that the email address user @ 126 is still verified by com. An example is found:
The code is as follows:
Eregi ("^ [_. 0-9a-z-] + @ ([0-9a-z] [0-9a-z-] +.) + [a-z] {2, 3} $", $ str) www.111cn.net
This seems more reasonable because it verifies the suffix name. although there are more than four top-level domain names, you only need to modify them a little. However, the email address user @ xxx and com 111cn.net can still pass verification. after careful check, it is found that the. is not escaped. Then, make a slight modification to it:
The code is as follows:
Eregi ("^ [_. 0-9a-z-] + @ ([0-9a-z] [0-9a-z-] +.) + [a-z] {2, 4} $)
Although it is easier to check the user name, it seems to have a good effect.
Example 1
The code is 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}) $ ", $ email ))
If ($ test_mx)
{
List ($ username, $ domain) = split ("@", $ email );
Return getmxrr ($ domain, $ mxrecords );
}
Else
Return true;
Else
Return false;
}
?>
Example 2 (self-written)
The code is as follows:
Function is_valid_email_address ($ email ){
$ Qtext = '[^ // x0d // x22 // x5c // x80-// xff]';
$ Dtext = '[^ // x0d // x5b-// x5d // x80-// xff]';
$ Atom = '[^ // x00-// x20 // x22 // x28 // x29 // x2c // x2e // x3a-// x3c '.
'// X3e // x40 // x5b-// x5d // x7f-// xff] + ';
$ Quoted_pair = '// x5c [// x00-// x7f]';
$ Domain_literal = "// x5b ($ dtext | $ quoted_pair) * // x5d ";
$ Quoted_string = "// x22 ($ qtext | $ quoted_pair) * // x22 ";
$ Domain_ref = $ atom;
$ Sub_domain = "($ domain_ref | $ domain_literal )";
$ Word = "($ atom | $ quoted_string )";
$ Domain = "$ sub_domain (// x2e $ sub_domain )*";
$ Local_part = "$ word (// x2e $ word )*";
$ Addr_spec = "$ local_part // x40 $ domain ";
Return preg_match ("! ^ $ Addr_spec $! ", $ Email )? 1: 0;
}
For more details, see: http://www.111cn.net/phper/php-cy/57193.htm
Pipeline code is as follows eregi ("^ [_ a-z0-9-] + (. [_ a-z0...