if (eregi("^[_.0-9a-z-]+@([0-9a-z][0-9a-z-]+.)+[a-z]$",$email)) {
echo "您的 E-Mail 通过初步检查";
}
?>
在这句话里,首先是应用了一个eregi函数,这个函数还算好理解。随便找本书,就能给你一段解释:
语法: int ereg(string pattern, string string, array [regs]);
返回值: 整数/数组
本函数以 pattern 的规则来解析比对字符串 string。
比对结果返回的值放在数组参数 regs 之中,regs[0] 内容就是原字符串 string、regs[1] 为第一个合乎规则的字符串、regs[2] 就是第二个合乎规则的字符串,余类推。若省略参数 regs,则只是单纯地比对,找到则返回值为 true。
而不太好理解的就是前面的这段正则表达式了:^[_.0-9a-z-]+@([0-9a-z][0-9a-z-]+.)+[a-z]$
在这段正则表达式中,"+"表示前面的字符串连续出现一个或多个;"^"表示下一个字符串必须出现在开头,"$"表示前一个字符串必须出现在结尾;
"."也就是".",这里""是转义符;""表示前面的字符串可以连续出现2-3次。"()"表示包含的内容必须同时出现在目标对象中。"[_.0-9a-z-]"表示包含在"_"、"."、"-"、从a到z范围内的字母、从0到9范围内的数字中的任意字符;
这样一来,这个正则表达式可以这样翻译:
"下面的字符必须在开头(^)"、"该字符必须包含在"_"、"."、"-"、从a到z范围内的字母、从0到9范围内的数字中([_.0-9a-z-])"、"前面这个字符至少出现一次(+)"、@、"该字符串由一个包含在从a到z范围内的一个字母、从0到9范围内的数字中的字符开头,后面跟至少一个包含在"-"、从a到z范围内任何一个字母、从0到9范围内任何一个数字中的字符,最后以.结束(([0-9a-z][0-9a-z-]+.))"、"前面这个字符至少出现一次(+)"、"从a到z范围内的字母出现2-3次,并以它结束([a-z]$)"
很繁杂是吧,对了,正因为这样,人们才使用正则表达式。

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

SublimeText3 Linux new version
SublimeText3 Linux latest version

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 Chinese version
Chinese version, very easy to use

Dreamweaver Mac version
Visual web development tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software