


PHP regular expression verification (email address, Url address, phone number, zip code)
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. Verification of email address
<?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. URL address verification
<?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 be helpful to everyone learning PHP programming.
The above introduces PHP regular expression verification (email address, Url address, phone number, postal code), including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



To learn more about open source, please visit: 51CTO Hongmeng Developer Community https://ost.51cto.com Running environment DAYU200:4.0.10.16SDK: 4.0.10.15IDE: 4.0.600 1. To create an application, click File- >newFile->CreateProgect. Select template: [OpenHarmony] EmptyAbility: Fill in the project name, shici, application package name com.nut.shici, and application storage location XXX (no Chinese, special characters, or spaces). CompileSDK10, Model: Stage. Device

The usage of return in C language is: 1. For functions whose return value type is void, you can use the return statement to end the execution of the function early; 2. For functions whose return value type is not void, the function of the return statement is to end the execution of the function. The result is returned to the caller; 3. End the execution of the function early. Inside the function, we can use the return statement to end the execution of the function early, even if the function does not return a value.

Function means function. It is a reusable code block with specific functions. It is one of the basic components of a program. It can accept input parameters, perform specific operations, and return results. Its purpose is to encapsulate a reusable block of code. code to improve code reusability and maintainability.

Source code: publicclassReturnFinallyDemo{publicstaticvoidmain(String[]args){System.out.println(case1());}publicstaticintcase1(){intx;try{x=1;returnx;}finally{x=3;}}}#Output The output of the above code can simply conclude: return is executed before finally. Let's take a look at what happens at the bytecode level. The following intercepts part of the bytecode of the case1 method, and compares the source code to annotate the meaning of each instruction in

The difference between comcn and com: 1. There are differences between comcn and com in terms of meaning, but there is no difference in access speed; 2. comcn is an international domain name and is a global top-level domain name for use by commercial institutions, while cn is a Chinese company domain name , domestic commercial institutions, domestic domain names, only enterprises can register; 3. The search priority is that cn will search for .cn first. After finding the .cn server, the .cn server will then search for .com; 4. cn is provided by cnnic China Internet Center Management, com's management organization is abroad.

In this article, we will learn about enumerate() function and the purpose of “enumerate()” function in Python. What is the enumerate() function? Python's enumerate() function accepts a data collection as a parameter and returns an enumeration object. Enumeration objects are returned as key-value pairs. The key is the index corresponding to each item, and the value is the items. Syntax enumerate(iterable,start) Parameters iterable - The passed in data collection can be returned as an enumeration object, called iterablestart - As the name suggests, the starting index of the enumeration object is defined by start. if we ignore

Detailed explanation of the role and function of the MySQL.proc table. MySQL is a popular relational database management system. When developers use MySQL, they often involve the creation and management of stored procedures (StoredProcedure). The MySQL.proc table is a very important system table. It stores information related to all stored procedures in the database, including the name, definition, parameters, etc. of the stored procedures. In this article, we will explain in detail the role and functionality of the MySQL.proc table

Vue3.2 setup syntax sugar is a compile-time syntax sugar that uses the combined API in a single file component (SFC) to solve the cumbersome setup in Vue3.0. The declared variables, functions, and content introduced by import are exposed through return, so that they can be used in Vue3.0. Problems in use 1. There is no need to return declared variables, functions and content introduced by import during use. You can use syntactic sugar //import the content introduced import{getToday}from'./utils'//variable constmsg='Hello !'//function func
