PHP Regular Expression validation Mailbox _php Tutorial

Source: Internet
Author: User
Tags php regular expression
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 ...

  • Related Article

    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.