Wed validation application of regular expressions (40)
Email address verification
<?<span>php </span><span>/*</span><span> 校验邮件地址</span><span>*/</span><span>function checkMail($email) { </span><span>//</span><span>用户名,由“\w”格式字符、“-”或“.”组成</span>$email_name= <span>"</span><span>\w|(\w[-.\w]*\w)</span><span>"</span><span>; </span><span>//</span><span>域名中的第一段,规则和用户名类似,不包括点号“.”</span>$code_at= <span>"</span><span>@</span><span>"</span><span>; $per_domain</span>= <span>"</span><span>\w|(\w[-\w]*\w)</span><span>"</span><span>; </span><span>//</span><span>域名中间的部分,至多两段</span>$mid_domain= <span>"</span><span>(\.</span><span>"</span> .$per_domain. <span>"</span><span>){0,2}</span><span>"</span><span>; </span><span>//</span><span>域名的最后一段,只能为“.com”、“.org”或“.net”</span>$end_domain= <span>"</span><span>(\.(com|net|org))</span><span>"</span><span>; $rs</span>=<span> preg_match( </span><span>"</span><span>/^{$email_name}@{$per_domain}{$mid_domain}{$end_domain}$/</span><span>"</span><span>, $email ); </span><span>return</span> (<span>bool</span><span>)$rs; } </span><span>//</span><span>测试,下面均返回成功</span>var_dump( checkMail(<span>"</span><span>root@localhost</span><span>"</span><span>) ); var_dump( checkMail(</span><span>"</span><span>Frank.Roulan@esun.edu.org</span><span>"</span><span>) ); var_dump( checkMail(</span><span>"</span><span>Tom.024-1234@x-power_1980.mail-address.com</span><span>"</span><span>) ); </span>?>
URL address verification
<?<span>php </span><span>/*</span><span> 校验URL地址</span><span>*/</span><span>function checkDomain($domain) { </span><span>return</span> ereg(<span>"</span><span>^(http|ftp)s? ://(www\.)?.+(com|net|org)$</span><span>"</span><span>, $domain); } $rs</span>= checkDomain(<span>"</span><span>www.taodoor.com</span><span>"</span>);<span>//</span><span>返回假</span>$rs= checkDomain(<span>"</span><span>http://www.taodoor.com</span><span>"</span>);<span>//</span><span>返回真</span>?>
Phone number
<?<span>php </span><span>/*</span><span> 校验电话号码</span><span>*/</span><span>function checkTelno($tel) { </span><span>//</span><span>去掉多余的分隔符</span>$tel= ereg_replace(<span>"</span><span>[\(\)\. -]</span><span>"</span>, <span>""</span><span>, $tel); </span><span>//</span><span>仅包含数字,至少应为一个6位的电话号(即没有区号)</span><span>if</span>(ereg(<span>"</span><span>^\d+$</span><span>"</span><span>, $tel)) { </span><span>return</span><span>true</span><span>; }</span><span>else</span><span>{ </span><span>return</span><span>false</span><span>; } } $rs</span>= checkTelno(<span>"</span><span>(086)-0411-12345678</span><span>"</span>);<span>//</span><span>返回真</span>?>
Postal code verification
<?<span>php </span><span>/*</span><span> 校验邮政编码</span><span>*/</span><span>function checkZipcode($code) { </span><span>//</span><span>去掉多余的分隔符</span>$code = preg_replace(<span>"</span><span>/[\. -]/</span><span>"</span>, <span>""</span><span>, $code); </span><span>//</span><span>包含一个6位的邮政编码</span><span>if</span>(preg_match(<span>"</span><span>/^\d{6}$/</span><span>"</span><span>, $code)) { </span><span>return</span><span>true</span><span>; }</span><span>else</span><span>{ </span><span>return</span><span>false</span><span>; } } $rs</span>= checkZipCode(<span>"</span><span>123456</span><span>"</span>);<span>//</span><span>返回真</span>?>
The above introduces the Wed verification application of regular expressions (40), including the relevant aspects. 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

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.

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

Usage and Function of Vue.use Function Vue is a popular front-end framework that provides many useful features and functions. One of them is the Vue.use function, which allows us to use plugins in Vue applications. This article will introduce the usage and function of the Vue.use function and provide some code examples. The basic usage of the Vue.use function is very simple, just call it before Vue is instantiated, passing in the plugin you want to use as a parameter. Here is a simple example: //Introduce and use the plug-in

The file_exists method checks whether a file or directory exists. It accepts as argument the path of the file or directory to be checked. Here's what it's used for - it's useful when you need to know if a file exists before processing it. This way, when creating a new file, you can use this function to know if the file already exists. Syntax file_exists($file_path) Parameters file_path - Set the path of the file or directory to be checked for existence. Required. Return file_exists() method returns. Returns TrueFalse if the file or directory exists, if the file or directory does not exist Example let us see a check for "candidate.txt" file and even if the file

The usage of js function function is: 1. Declare function; 2. Call function; 3. Function parameters; 4. Function return value; 5. Anonymous function; 6. Function as parameter; 7. Function scope; 8. Recursive function.

With the development of the Internet, SOA (service-oriented architecture) has become an important technical architecture in today's enterprise-level systems. Services in the SOA architecture can be reused, reorganized and extended, while also simplifying the system development and maintenance process. As a widely used Web programming language, PHP also provides some function libraries for implementing SOA. Next, we will detail how to use SOA functions in PHP. 1. The basic concept of SOA. SOA is a distributed system development idea and architecture.

Introduction to the Function interface in Java 8 Java 8 provides a functional interface Function. This interface represents doing some operations on a parameter and then returning the value after the operation. This interface has an abstract method apply, which indicates the operation on the parameters. //Definition of JavaFunction interface @FunctionalInterfacepublicinterfaceFunction{Rapply(Tt);defaultFunctioncompose(Function
