search
  • Sign In
  • Sign Up
Password reset successful

Follow the proiects vou are interested in andi aet the latestnews about them taster

Table of Contents
php regular expression verification (email address, Url address, phone number, postal code), regular expression url
Articles you may be interested in:
Home Backend Development PHP Tutorial PHP regular expression verification (email address, Url address, phone number, zip code), regular expression url_PHP tutorial

PHP regular expression verification (email address, Url address, phone number, zip code), regular expression url_PHP tutorial

Jul 12, 2016 am 08:57 AM
php regular expression verify

php regular expression verification (email address, Url address, phone number, postal code), regular expression url

The content that needs to be verified in the example of this article: Email address , Url address, phone number, postal code , the verification method is shared with everyone for your reference, the specific content is as follows

1. Email address verification

<?php
/* 校验邮件地址*/
function checkMail($email) {
//用户名,由“\w”格式字符、“-”或“.”组成
$email_name= "\w|(\w[-.\w]*\w)";
//域名中的第一段,规则和用户名类似,不包括点号“.”
$code_at= "@";
$per_domain= "\w|(\w[-\w]*\w)";
//域名中间的部分,至多两段
$mid_domain= "(\." .$per_domain. "){0,2}";
//域名的最后一段,只能为“.com”、“.org”或“.net”
$end_domain= "(\.(com|net|org))";
$rs= preg_match(
"/^{$email_name}@{$per_domain}{$mid_domain}{$end_domain}$/",
$email
);
return (bool)$rs;
}
//测试,下面均返回成功
var_dump( checkMail("root@localhost") );
var_dump( checkMail("Frank.Roulan@esun.edu.org") );
var_dump( checkMail("Tom.024-1234@x-power_1980.mail-address.com") );
?>

2. Verification of URL address

<?php
/* 校验URL地址*/
function checkDomain($domain)
{
return ereg("^(http|ftp)s? ://(www\.)?.+(com|net|org)$", $domain);
}
$rs= checkDomain("www.taodoor.com");//返回假
$rs= checkDomain("http://www.taodoor.com");//返回真
?>

3. Phone number

<?php
/* 校验电话号码*/
function checkTelno($tel)
{
//去掉多余的分隔符
$tel= ereg_replace("[\(\)\. -]", "", $tel);
//仅包含数字,至少应为一个6位的电话号(即没有区号)
if(ereg("^\d+$", $tel))
{
return true;
}else{
return false;
}
}
$rs= checkTelno("(086)-0411-12345678");//返回真
?>

4. Postal code verification

<?php
/* 校验邮政编码*/
function checkZipcode($code)
{
//去掉多余的分隔符
$code = preg_replace("/[\. -]/", "", $code);
//包含一个6位的邮政编码
if(preg_match("/^\d{6}$/", $code))
{
return true;
}else{
return false;
}
}
$rs= checkZipCode("123456");//返回真
?>

I hope this article will help you learn PHP programming.

Articles you may be interested in:

  • Regular expressions commonly used for form verification under PHP
  • PHP regular expression verification problems in Chinese
  • PHP IPV6 Regular expression verification code
  • php mobile phone number verification regular expression
  • php password password verification regular expression (8-bit length limit)
  • php URL verification regular expression
  • php user registration information verification regular expression
  • php email address regular expression verification

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1110079.htmlTechArticlephp regular expression verification (email address, Url address, phone number, zip code), regular expression url This article Contents that need to be verified in the instance: email address, URL address, phone number...
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

Undress AI Tool

Undress AI Tool

Undress images for free

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

ArtGPT

ArtGPT

AI image generator for creative art from text prompts.

Stock Market GPT

Stock Market GPT

AI powered investment research for smarter decisions

Popular tool

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)

How to dynamically set arbitrary depth value of nested array in PHP How to dynamically set arbitrary depth value of nested array in PHP Mar 04, 2026 am 11:15 AM

This article introduces a safe and efficient method to use key path arrays (such as ['key1', 'key2', 'key3']) to assign values ​​to the last nodes of multi-dimensional associative arrays, solve the problem of reference failure caused by value transfer, and take into account key existence verification.

Where can I see the PHP operator priority table_php official operator priority [Reference] Where can I see the PHP operator priority table_php official operator priority [Reference] Mar 02, 2026 am 11:45 AM

The official description of PHP operator precedence is located at https://www.php.net/manual/en/language.operators.precedence.php. You need to directly search for "operatorprecedence" or manually enter the URL to access; == and === have the same priority and belong to the same level; error-prone combinations include &&/|| and and/or, ?: and ??, new and []; complex expressions must be bracketed.

Number statistics in pyramid loop in PHP: correct counting method of total, odd and even numbers Number statistics in pyramid loop in PHP: correct counting method of total, odd and even numbers Mar 04, 2026 pm 01:30 PM

This article explains in detail how to accurately count the total number, odd number and even number of all generated numbers in the PHP pyramid printing loop, correct common logic errors (such as misuse of variables, confusion of counting objects), and provide runnable examples and key precautions.

PHP batch processing of color mode and resolution of pictures in PPT PHP batch processing of color mode and resolution of pictures in PPT Mar 02, 2026 am 10:18 AM

To read PPTX images with PHP, you need to decompress the ZIP package first, because the images are stored in the ppt/media/ directory; directly calling the image function will report an error; you must use ZipArchive to decompress, Imagick to process CMYK to RGB conversion and scaling, and update the rels and [Content_Types].xml files simultaneously.

How to deal with character sets after mysql upgrade_mysql encoding migration instructions How to deal with character sets after mysql upgrade_mysql encoding migration instructions Feb 09, 2026 pm 07:17 PM

After the MySQL 8.0 upgrade, the default character set becomes utf8mb4, but the old table character set remains unchanged; latin1/utf8 tables need to be manually migrated, and the source character set must be specified when exporting. ALTERTABLECONVERT will re-encode the data, and the connection layer must explicitly declare utf8mb4.

How to install ThinkPHP with composer_Steps to deploy TP framework using composer How to install ThinkPHP with composer_Steps to deploy TP framework using composer Feb 12, 2026 am 06:27 AM

The ThinkPHP stable version should be clearly specified, such as using composercreate-projecttopthink/thinktp6^6.3 to install the TP6.3LTS version to avoid pulling non-production-ready beta versions because dev-master has switched to the TP8 preview version.

Correct way to embed PayPal JavaScript SDK in PHP logic Correct way to embed PayPal JavaScript SDK in PHP logic Mar 04, 2026 pm 01:12 PM

This article explains in detail how to safely and standardly inject PayPalJSSDK front-end code in PHP conditional branches (such as payment method judgment) to avoid echo confusing output, coding conflicts and HTML structure damage, and ensure that buttons are rendered normally and the order process is completed.

How to optimize php8.5fpm configuration_php8.5fpm process management parameter tuning guide How to optimize php8.5fpm configuration_php8.5fpm process management parameter tuning guide Mar 02, 2026 am 10:33 AM

PHP8.5 has not yet been released. The latest stable version is 8.3, and 8.4 is in the RC stage. To confirm the real version, you must execute php-fpm-v or php--rifpm instead of relying on directory names, image tags or configuration file naming.

Related articles