Home Backend Development PHP Tutorial PHP regular expression verification email_PHP tutorial

PHP regular expression verification email_PHP tutorial

Jul 13, 2016 pm 04:56 PM
php cannot code domain name big regular use expression Mail verify

Email verification codes are mostly unable to verify one-letter domain names or one-letter usernames, 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 length judgment yourself;

2, supports domain name suffixes such as .net.cn and .com.cn;

3. The email name part starts with a letter or number, and can have "-" and "_" symbols in the middle;

4. The domain name part starts with a letter or number, and there can be "-" and "_" symbols in the middle;


PHP email verification regular expression

Example
The code is as follows
 代码如下 复制代码

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

Copy code

 代码如下 复制代码

/**
 * 自己修整的一个邮箱正则表达式
 * 琼台博客
 */
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 '邮箱格式正确';
}else{
    echo '邮箱格式错误';
}

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

 代码如下 复制代码

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"验证成功!是邮箱地址。";
}
else
{
    echo"不是邮箱地址!";
}
?>

The code is as follows Copy code
/** * An email regular expression modified by myself * Qiongtai 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 'The email format is correct'; }else{ echo 'Email format error'; } Email verification 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 "Verification successful! It's the email address."; } else { Echo "Not an email address!"; } ?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/631574.htmlTechArticleEmail verification codes are mostly unable to verify one-letter domain names or one-letter usernames, such as: i@fufuok. com or fufu@9.cn. The solution is as follows: 1. Do not judge the total length, judge the length...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

okx Ouyi official website registration portal 2025 okx Ouyi official website registration portal 2025 Mar 04, 2025 pm 11:45 PM

OKX Ouyi is a leading cryptocurrency trading platform. This article will provide detailed steps to guide you on how to register an OKX Ouyi official website account. You will learn how to access the official website, choose the registration method, fill in the necessary information, and complete the registration process. The article also contains information about precautions, such as the importance of using real personal information and setting a strong password.

Sesame Open Door Exchange Web Page Login Latest version gateio official website entrance Sesame Open Door Exchange Web Page Login Latest version gateio official website entrance Mar 04, 2025 pm 11:48 PM

A detailed introduction to the login operation of the Sesame Open Exchange web version, including login steps and password recovery process. It also provides solutions to common problems such as login failure, unable to open the page, and unable to receive verification codes to help you log in to the platform smoothly.

gateio exchange app old version gateio exchange app old version download channel gateio exchange app old version gateio exchange app old version download channel Mar 04, 2025 pm 11:36 PM

Gateio Exchange app download channels for old versions, covering official, third-party application markets, forum communities and other channels. It also provides download precautions to help you easily obtain old versions and solve the problems of discomfort in using new versions or device compatibility.

How to register and download the latest app on Bitget official website How to register and download the latest app on Bitget official website Mar 05, 2025 am 07:54 AM

This guide provides detailed download and installation steps for the official Bitget Exchange app, suitable for Android and iOS systems. The guide integrates information from multiple authoritative sources, including the official website, the App Store, and Google Play, and emphasizes considerations during download and account management. Users can download the app from official channels, including app store, official website APK download and official website jump, and complete registration, identity verification and security settings. In addition, the guide covers frequently asked questions and considerations, such as

Sesame Open Door Login Registration Entrance gate.io Exchange Registration Official Website Entrance Sesame Open Door Login Registration Entrance gate.io Exchange Registration Official Website Entrance Mar 04, 2025 pm 04:51 PM

Gate.io (Sesame Open Door) is the world's leading cryptocurrency trading platform. This article provides a complete tutorial on spot trading of Gate.io. The tutorial covers steps such as account registration and login, KYC certification, fiat currency and digital currency recharge, trading pair selection, limit/market transaction orders, and orders and transaction records viewing, helping you quickly get started on the Gate.io platform for cryptocurrency trading. Whether a beginner or a veteran, you can benefit from this tutorial and easily master the Gate.io trading skills.

gate.io official login web version Sesame Open Door Trading Platform web version login web version gate.io official login web version Sesame Open Door Trading Platform web version login web version Mar 04, 2025 pm 04:33 PM

The login method of the Sesame Open Door Trading Platform is convenient. Users only need to visit their official website (please search for the domain name yourself), enter the registered email/mobile phone number and password to log in. The platform may enable security verification mechanisms such as 2FA to ensure account security.

What are the routines of digital currency contracts? How to play a digital currency contract? What are the routines of digital currency contracts? How to play a digital currency contract? Mar 03, 2025 pm 07:06 PM

Digital currency contract trading: Investment strategies that coexist with high returns and potential risks. Digital currency contract trading. Unlike spot trading, investors need to predict the ups and downs of the price of digital currency and choose to go long or short contracts to make a profit. Contract trading usually uses leverage, with potential returns higher than spot trading, but also accompanied by higher risks. This article will reveal common pitfalls in digital currency contract trading and provide detailed steps for contract trading on Ouyi OKX Exchange. Risks and Traps of Digital Currency Contract Trading There are many risks hidden in the market for digital currency contracts, and criminals or platforms may use rule loopholes to make profits. Common pitfalls include: Price manipulation: manipulate market prices through centralized trading, artificially raising or lowering prices to make profits. Information asymmetry: platform or transaction

Ouyi okx trading platform app official website registration portal Ouyi okx trading platform app official website registration portal Mar 04, 2025 pm 11:27 PM

OKX trading platform, a digital asset trading platform trusted by global users. The platform provides a variety of digital asset trading services, including spot trading, futures trading, option trading, etc.

See all articles