Php regular expression verification email _ PHP Tutorial

Source: Internet
Author: User
Tags php email
Php regular expression verification mailbox. 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, the length of the Mail authentication code is mostly not to verify a letter of the domain name 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. 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:

Preg_match ("/^ [0-9a-zA-Z] + @ ([0-9a-zA-Z] +) [.]) + [a-z] {2, 4} $/I", $ email );

Instance

The code is as follows:

/**
* A self-edited regular mailbox expression
* Qiongtai blog
*/
Echo' ';
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:

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"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.