求用户注册时php正则表达式验证

cnk46 2010-01-12 01:44:14
1、用户名:5-20位,字母、数字、汉字或下划线组成。

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

3、昵称:2-20位,由字母、数字、汉字组成

4、email验证

注意:是php的哈,不是JavaScript的
...全文
1501 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
cuihan1015 2010-01-16
  • 打赏
  • 举报
回复
不知道合不合你的要求! 刚才写的!
编码是 UTF-8

if($_POST){
$reg_Id = $_POST['id'];
$reg_Pwd = $_POST['pwd'];
$reg_Email = $_POST['email'];
$pcre_Id = '/^[\x{4e00}-\x{9fa5}a-zA-Z0-9_]{5,20}$/u';
$pcre_Pwd = '/^[0-9a-zA-Z]{6,20}$/';
$pcre_Email = '/^[a-zA-Z][0-9a-zA-Z_]+@([0-9a-zA-Z][0-9a-zA-Z.]{0,30}\.)[a-zA-Z]{2,4}$/';
if(preg_match($pcre_Id,$reg_Id)){
echo '用户名匹配'."<BR>";
}else{
echo '用户名不匹配'."<BR>";
}
if(preg_match($pcre_Pwd,$reg_Pwd)){
echo '密码匹配'."<BR>";
}else{
echo '密码不匹配'."<BR>";
}
if(preg_match($pcre_Email,$reg_Email)){
echo '邮箱匹配'."<BR>";
}else{
echo '邮箱不匹配'."<BR>";
}
}

?>
<form name="form1" method="POST" action="">
用户名:<input type="text" name="id" id="id" />
密 码:<input type="password" name="pwd" id="pwd" />
邮 箱:<input type="text" name="email" id="email" />
<input type="submit" name="sub" id="sub" value="验证" />
</form>
inyiwang 2010-01-15
  • 打赏
  • 举报
回复
系统函数preg-match,没有使用吧。。
cnk46 2010-01-14
  • 打赏
  • 举报
回复
有这个错误啊,怎么办?
Warning: preg_match() [function.preg-match]: Compilation failed: missing terminating ] for character class at offset 。。。


[Quote=引用 1 楼 jakey9826 的回复:]
PHP codepreg_match("/[\w_\x7f-\xff\]{5,20}/i",$str)preg_match("/[\w]{6,20}/i",$str);preg_match("/[\w\x7f-\xff\]{2,20}/i",$str)preg_match("/[\w_\x7f-\xff\]/i",$str)preg_match("/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/",$str)


[/Quote]
xtb520fq 2010-01-14
  • 打赏
  • 举报
回复
preg_match("/^[a-z]([a-z0-9])+@([a-z0-9])+[\.][a-z]{2,3}$/",$email)
cnk46 2010-01-14
  • 打赏
  • 举报
回复
有这个错误啊,怎么办?
Warning: preg_match() [function.preg-match]: Compilation failed: missing terminating ] for character class at offset 。。。


[Quote=引用楼主 cnk46 的回复:]
1、用户名:5-20位,字母、数字、汉字或下划线组成。

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

3、昵称:2-20位,由字母、数字、汉字组成

4、email验证

注意:是php的哈,不是JavaScript的
[/Quote]
cnk46 2010-01-14
  • 打赏
  • 举报
回复
看来要另外开贴问了?
cnk46 2010-01-14
  • 打赏
  • 举报
回复
ding
cnk46 2010-01-14
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 jakey9826 的回复:]
PHP codepreg_match("/[\w_\x7f-\xff\]{5,20}/i",$str)
preg_match("/[\w]{6,20}/i",$str);
preg_match("/[\w\x7f-\xff\]{2,20}/i",$str)
preg_match("/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/",$str)
[/Quote]


jakey9826 ,您好啊,你给的正则第1、3个有警告信息啊,Warning: preg_match() [function.preg-match]: Compilation failed: missing terminating ] for character class at offset 14 in D:\work\Apache2.2\htdocs\test.php on line 3


是不是php不支持这种写法,希望得到解答,立马结账!谢谢。
苍蝇①号 2010-01-12
  • 打赏
  • 举报
回复
支持楼上的
jf
骄傲青蛙 2010-01-12
  • 打赏
  • 举报
回复
刚看到帖就有人回复了,

有一个email验证的我不同意
preg_match("/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/", $str)

1 域名中能用 “+” 这个?

2 域名后缀,即 “@” 之后不能匹配中文域名
gaijf 2010-01-12
  • 打赏
  • 举报
回复
使用我佛山人js验证
程序猿之殇 2010-01-12
  • 打赏
  • 举报
回复
preg_match("/[\w_\x7f-\xff\]{5,20}/i",$str)
preg_match("/[\w]{6,20}/i",$str);
preg_match("/[\w\x7f-\xff\]{2,20}/i",$str)
preg_match("/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/", $str)
程序猿之殇 2010-01-12
  • 打赏
  • 举报
回复
preg_match("/[\w_\x7f-\xff\]{5,20}/i",$str)
preg_match("/[\w]{6,20}/i",$str);
preg_match("/[\w\x7f-\xff\]{2,20}/i",$str)
preg_match("/[\w_\x7f-\xff\]/i",$str)
preg_match("/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/", $str)


21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧