Home > php教程 > php手册 > body text

php用户注册信息验证正则表达式

WBOY
Release: 2016-06-06 19:36:48
Original
1802 people have browsed it

各种网页脚本也都常用“正则表达式”(regular expression)对我们信息进行验证,判断是否合法,本文为大家介绍了php用户注册验证正则表达式,需要的朋友可以参

下面这个正则验证用户名的方法原则是这样的用户名必须是由字母带数字带定划线组成了,下面一起来看看例子吧.

1.检查用户名是否符合规定“两位以上的字母,数字,或者下划线”,代码如下:

/** * 检查用户名是否符合规定 * * @param STRING $username 要检查的用户名 * @return TRUE or FALSE */ function is_username($username) { $strlen = strlen($username); if (!preg_match("/^[a-zA-Z0-9_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]+$/", $username)) //开源软件:phpfensi.com { return false; } elseif (20

两位以上的字母,数字,或者下划线:^[a-zA-Z0-9_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]+$.

注:在这里,字母是a-z,A-Z,以及从127 到255(0x7f-0xff)的 ASCII 字符

2、密码:6—20位,由字母、数字组成,代码如下:

function isPWD($value,$minLen=5,$maxLen=16){ $match='/^[\\~!@#$%^&*()-_=+|{}\[\],.?\/:;\'\"\d\w]{'.$minLen.','.$maxLen.'}$/'; $v = trim($value); if(emptyempty($v)) return false; return preg_match($match,$v); }

3、email验证,代码如下:

function isEmail($value,$match='/^[\w\d]+[\wd-.]*@[w\d-.]+\.[\w\d]{2,10}$/i') { $v = trim($value); if(emptyempty($v)) return false; return preg_match($match,$v); }

source:php.cn
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!