Mailbox verification code is mostly a domain name or a letter user name that cannot be verified by a letter, such as: I @fufuok.com or fufu@9.cn. The solution is as follows:
1. Do not judge the total length. You can add the total length;
2. Supports domain name suffixes such as .net.cn and .com.cn;
3. The mailbox name must start with a letter or number and can contain "-" and "_" in the middle;
4. The domain name must start with a letter or number, with the "-" and "_" characters in the middle;
PHP email verification 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 |
/** * A self-edited regular mailbox expression * Qiongtai blog */ Echo '<meta charset = "UTF-8"/> '; Function c_email ($ email ){ $ Reg = '/^ ([a-zA-Z0-9] {}) ([_-.])? ([A-zA-Z0-9] {}) * @ ([a-zA-Z0-9] {}) ([-_])? ([A-zA-Z0-9] {}) * (. [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 '; } |
Email Verification
The Code is as follows: |
Copy code |
<? Php 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 "<script language = 'javascript '> alert ('verified successfully') </script> "; } Else { Echo "<script language = 'javascript '> alert ('verification failed') </script> "; } } } $ 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 "Verification Successful! Is the email address. "; } Else { Echo "not the email address! "; } ?> |