Most of the mailbox verification code is a domain name that cannot be verified with a letter or a letter of the user name, such as: I@fufuok.com or fufu@9.cn. Here's how to fix it:
1, does not make the total length judgment, the length judgment may add oneself;
2, support. net.cn,.com.cn such a domain name suffix;
3, the mailbox Name section begins with a letter or a number, the middle can have "-" and "_" symbol;
4, the Domain name section begins with a letter or a number, the middle can have "-" and "_" symbol;
PHP Mailbox Validation Regular expression
The code is as follows |
Copy Code |
Preg_match ("/^[0-9a-za-z]+@ ([0-9a-za-z]+) [.]) +[a-z]{2,4}$/i ", $email); |
Instance
The code is as follows |
Copy Code |
/** * Self-trimming a mailbox regular expression * Jones Taiwan Blog */ Echo ' ; function C_email ($email) { $reg = '/^ ([a-za-z0-9]{1,20}) ([_-.])? ([a-za-z0-9]{1,20})) *@ ([a-za-z0-9]{1,20}) ([[-_])? ( [A-za-z0-9] {1,20})) *(. [A-z] {2,4}) {1,2}$/'; if (Preg_match ($reg, $email)) return true; return false; } $email = ' mail@lizhong.me '; $check _result = C_email ($email); if ($check _result) { Echo ' mailbox format is correct '; }else{ Echo ' mailbox format error '; } |
Mailbox Validation Class
The code is as follows |
Copy Code |
Class Reg { Public $mail; function __construct () { $this->mail = $_post["Mail"]; } function Regmail () { if (Preg_match ("/^[0-9a-za-z]+" (?: [_-][a-z0-9-]+) *@[a-za-z0-9]+ (?: [-.] [a-za-z0-9]+) *. [a-za-z]+$/i ", $this->mail)) { echo ""; } Else { echo ""; } } } $r = new Reg (); $r->regmail (); $strings = "abc@163.com"; if (Preg_match ("/^[0-9a-za-z]+" (?: [_-][a-z0-9-]+) *@[a-za-z0-9]+ (?: [-.] [a-za-z0-9]+) *. [a-za-z]+$/i ", $strings)) { echo "Verified success! is the e-mail address. "; } Else { echo "is not an email address! "; } ?> |
http://www.bkjia.com/PHPjc/631574.html www.bkjia.com true http://www.bkjia.com/PHPjc/631574.html techarticle Most of the mailbox verification code is a domain name that cannot be verified with a letter or a letter of the user name, such as: I@fufuok.com or fufu@9.cn. The solution is as follows: 1, do not judge the total length, the length of the sentence ...