1、用户名:5-20位,字母、数字、汉字或下划线组成。 2、密码:6—20位,由字母、数字组成 3、昵称:2-20位,由字母、数字、汉字组成 4、email验证注意:是php的哈,不是JavaScript的

解决方案 »

  1.   

    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)
      

  2.   

    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)
      

  3.   

    刚看到帖就有人回复了, 有一个email验证的我不同意
    preg_match("/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/", $str)1 域名中能用 “+” 这个?2 域名后缀,即 “@” 之后不能匹配中文域名
      

  4.   

    有这个错误啊,怎么办?
    Warning: preg_match() [function.preg-match]: Compilation failed: missing terminating ] for character class at offset 
      

  5.   

    有这个错误啊,怎么办? 
    Warning: preg_match() [function.preg-match]: Compilation failed: missing terminating ] for character class at offset  
      

  6.   

    preg_match("/^[a-z]([a-z0-9])+@([a-z0-9])+[\.][a-z]{2,3}$/",$email)
      

  7.   

    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不支持这种写法,希望得到解答,立马结账!谢谢。
      

  8.   

    系统函数preg-match,没有使用吧。。
      

  9.   

    不知道合不合你的要求! 刚才写的! 
    编码是 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" />
    密&nbsp;码:<input type="password" name="pwd" id="pwd" />
    邮&nbsp;箱:<input type="text" name="email" id="email" />
    <input type="submit" name="sub" id="sub" value="验证" />
    </form>