php正则注册界面,PHP正则

发布时间:2022-11-21

本文目录一览:

  1. PHP用正则表达式做注册页面
  2. PHP 注册表单的正则验证
  3. 求PHP用户名注册验证正则表达式(6-16位字符,字母开头,只包含字母数字下划线)可支持中文
  4. 用PHP语言制作一个注册页面和一个登录页面,内容自选。 要求用户注册数据在另一个页面显示,
  5. PHP 注册页面注册后,展示页面显示展示信息,然后返回注册页面时包含注册的信息
  6. 请写PHP高手帮帮忙!

PHP用正则表达式做注册页面

  • 账号:'/^[a-zA-Z_][\w_]$/'
  • 密码:'/^\w{6,}$/'
  • 手机:'/^1[3458]\d{9}$/'
  • 邮箱:'/^\w{4,20}@\w+\.((\w{3}|\w{3}\.\w{2})|\w{2})$/'
if(preg_match(表达式, 内容,$arr)){
    echo '匹配成功';
}else {
    echo '匹配失败';
}

PHP 注册表单的正则验证

我举个例子撒 假如你表单是这么写 用户名:<input name="username" value="" /> 注意name为 username 表单用POST方式提交 即form 的method 属性为post 在PHP中这么验证: 假设我要这个用户名只能是 10-32位 数字英文下划线组合,且第一位必须字母

empty($_POST['username']) && $_POST['username'] = '';
if(!preg_match('/^[a-zA-Z0-9\_]{10,32}$/',$_POST['username'])) exit('用户名不合法');
if(!preg_match('/^[a-zA-Z]/',$_POST['username'])) exit('第一位必须是字母');

正则表达式就是 两个/中间的部分了

  • ^表示前面没有任何字符了
  • $表示结尾没有任何字符了
  • [a-zA-Z0-9\_]表示匹配规则集
  • 每个字符都必须是 小写字母a-z 或 大写字母A-Z 或 数字0-9 或者下划线_
  • {16,32} 表示匹配次数为 16次到32次,少于16 或多于32 均为不合格,如果不限制长度 可以直接写为 +[a-zA-Z0-9]+ 或者指定一个长度 {10} 关于其他的表达式 百度搜索下就行了,都是通用的 例如:
  • 匹配手机号 /^1[0-9]{10}$/

求PHP用户名注册验证正则表达式(6-16位字符,字母开头,只包含字母数字下划线)可支持中文

自我矛盾,只包含字母数字下划线 --中文放哪??

/^[A-Z][a-z\d\_]{5,15}$/i

用PHP语言制作一个注册页面和一个登录页面,内容自选。 要求用户注册数据在另一个页面显示,

如果只是为了展示效果的话那就用两个界面就可以了,第一个表单,给action的值的地址是第二个界面,第二个界面就写个欢迎就好啦

PHP 注册页面注册后,展示页面显示展示信息,然后返回注册页面时包含注册的信息

你这个是分步完成的吧,你是指一个连贯的动作,还是指,分步操作,注册完成后跳转到展示界面;点击注册界面时,包含当前登录人的注册信息?

请写PHP高手帮帮忙!

这个注册页面是我自己以前写的,希望对你有所帮助! 有什么问题你可以来我的baidu空间一起交流! 我的空间地址是: 关于php: 为个是php的运行环境安装: 对了你没事匿名做什么?? 那10分加在这题上多好!(^_^) 有什么不懂的你可以发消息给我!

/*****************************因时间问题,本因将需要存入数据库中的数据进行格式化,在存储进去
输出时,反转义****************
if(!get_magic_quotes_gpc())//判断php魔术特性是否打开了
{
    addslashes();//转义
    stripslashes();//反转义
}
**********************************************************************************************************/
session_start();//开始一个会话,检查会话ID是否存在,如果存在将会话ID所属会话变量载入,否则创建一个新的会话ID
//先获取所有的表单值,并去除它们的前后空格
$user= trim($_POST['user']);
$pwd= trim($_POST['pwd']);
$pwd2= trim($_POST['pwd2']);
$email=trim($_POST['email']);
$yzm= trim($_POST['yzm']);
$redio= trim($_POST['redio']);
$quzi= trim($_POST['quzi']);
$answer=trim($_POST['answer']);
$name= trim($_POST['name']);
$sex= trim($_POST['sex']);
$date= trim($_POST['year']).trim($_POST['month']).trim($_POST['day']);
$qq= trim($_POST['qq']);
$diqu= trim($_POST['diqu']);
echo "<ol class='tishi'>";
/**************************注:在这里,只要一有错识就给$error就赋上一个值,省的还要将有可能出错的**********************/
if(!empty($_POST['submit']))//如果按钮不为空
{
    if(!empty($user)!empty($pwd)!empty($pwd2)!empty($email)!empty($yzm)!empty($redio))//如果六个必埴项都不为
    {
        if(strlen($user) < 4 || strlen($user) > 18)//如果$user的字符长度小于"4" 或 大于"18"
        {
            echo "<li>用户名,输入范围不得小于4个字符或大于18个字符</li><br>";
            $error="I\'ve found still another mistake"; //有错误$error赋值
        }
        else //否则,即$user的字符长度大于"4" 或 小于"18"
        {
            require("lookup_user.php");//包含一个文件
            if($count > 0)//如果$count的值大于"0"
            {
                echo "<font color='red'>对不起,该用户名已存在!</font>";
                $error="I\'ve found still another mistake";
            }
            mysql_close($link);//关闭连接
        }
        /************ 必选项验证 **********/
        if($pwd != $pwd2)//验证密码是否相同
        {
            echo "<li>对不起两次输入的密码不相同!</li><br>";
            $error="I\'ve found still another mistake";
        }
        function str_len($object,$write)//要使用好几次,写个函数节省代码
        {
            if(!empty($object)) //必选项和可选项都可以进入到这里的,而可选项是可以为空(不填)的,所以要判断一下!
            {
                if(strlen($object) < 4 || strlen($object) > 18)//如果形参小于"4" 或者 大于"18"
                {
                    echo "<li>".$write.",输入范围不得小于4个字符或大于18个字符</li><br>";
                    $error="I\'ve found still another mistake";
                }
            }
        }
        str_len("$pwd","密码");//调用函数
        str_len("$pwd2","确认密码");
        if(!eregi('^[a-zA-Z0-9_\-\.]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$',$email))//用正则表达式来检查eamil的格式
        {
            echo "<li>您的电子邮件格式输入错误,请输入有效的电子邮件!</li><br>";
            $error="I\'ve found still another mistake";
        }
        if($yzm != $_POST['hidden_yzm'])//检查验证码输入是否错误
        {
            echo "<li>对不起你的验证码输入错误!</li><br>";
            $error="I\'ve found still another mistake";
        }
        if($redio != "yes")//没有同意协议
        {
            echo "<li>你不同意使用许可协议,注册无法进行!</li><br>";
            $error="I\'ve found still another mistake";
        }
        /*********************************** 可选项验证 **********************************************/
        echo str_len($quiz,"密码提示问题");//调用函数
        echo str_len($answer,"密码回答问题");
        echo str_len($name,"姓名");
        if($quiz == $answer)//为了安全性,密码提示问题和密码回答问题的值,不应该相同
        {
            echo "<li>密码提示问题和密码回答问题的值,不应该相同!</li>";
            $error="I\'ve found still another mistake";
        }
        if(!empty($qq))//可选项要判断是否为空
        {
            if(!eregi('^[0-9]+$',$qq))//用正则表达式来检查qq的格式
            {
                echo "<li>QQ号必须为(0-9)之间的数字!</li>";
                $error="I\'ve found still another mistake";
            }
        }
        echo "</ol>";
    }
    else//必选项只要有一个为空
    {
        echo "<font size='3 'color='red'>用户信息必填项没有填写完整!</font>";
        $error="I\'ve found still another mistake";
    }
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" ""
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title></title>
    <style type="text/css">
        <!--
        div {
            font-family: "宋体";
            font-size: 12px;
            font-style: normal;
            line-height: normal;
            font-weight: normal;
            font-variant: normal;
            color: #000000;
        }
        .style4 {color: #FF0000}
        .tishi {
            font-family: "宋体";
            font-size: 14px;
            font-weight: bold;
            color: #FF0000;
        }
        .style6 {color: #FF0000; font-size: 14px; }
        -->
    </style>
</head>
<body>
<form name="form1" method="post" action="">
    <table width="87%" height="329" border="0" align="center" cellpadding="0" cellspacing="1" bordercolor="#D4D0C8">
        <tr bgcolor="#CCCCCC">
            <td colspan="2"><div align="center">
                <h2>注册页面 </h2>
            </div></td>
        </tr>
        <tr bgcolor="#CCCCCC">
            <td colspan="2"><div align="center"><strong> 为了密码的安全,请仔细填写(区分大小写)!请注意栏目后加 <span class="style4">*</span>为必填项</strong></div></td>
        </tr>
        <tr bgcolor="#CCCCCC">
            <td colspan="2"><div align="center" class="style4">必填项没填写完整,注册无法进行!</div></td>
        </tr>
        <tr bgcolor="#CCCCCC">
            <td width="13%"><div align="right">用户名:</div></td>
            <td width="87%">
                <div align="left">
                    <input name="user" type="text" id="user" size="25" maxlength="18" <?php if(!empty($user)) echo "value=".$user;?>
                    (字符数:4-18之间)<span class="style4">*</span>
                    <input type="submit" name="lookup" value="检查用户名是存在">
                    <?php
                    //在数据库中查找用户是否存在
                    if(!empty($_POST['lookup']))//如果检查用户名按钮不为空
                    {
                        if(strlen($user) < 4 || strlen($user) > 18)//如果$user的字符长度小于4 或 大于18
                        {
                            echo "<font color='red'>用户名,输入范围不得小于4个字符或大于18个字符</font>";
                            $error="I\'ve found still another mistake";
                        }
                        else
                        {
                            require("lookup_user.php");//包含一个文件
                            if($count > 0)//如果$count大于"0"
                            {
                                echo "<font color='red'>对不起,该用户名已存在!</font>";
                                $error="I\'ve found still another mistake";
                            }
                            else//否则,即$count小于"0"
                            {
                                echo "<font color='red'>该用户名可用!</font>";
                            }
                            mysql_close($link);//关闭连接
                        }
                    }
                    ?>
                </div>
            </td>
        </tr>
        <tr bgcolor="#CCCCCC">
            <td><div align="right">密码: </div></td>
            <td><div align="left">
                <input name="pwd" type="password" id="pwd" size="25" maxlength="18">
                <!--如果$pwd不为空,就将它设为表单的初始值,以下雷同!-->
                (字符数:4-18之间)<span class="style4">*</span>
                <input name="hid_pwd" type="hidden" <?php if(!empty($pwd)) echo "value=".$pwd;?>
            </div></td>
        </tr>
        <tr bgcolor="#CCCCCC">
            <td><div align="right">确认密码:</div></td>
            <td>
                <div align="left">
                    <input name="pwd2" type="password" id="pwd2" value="" size="25" maxlength="18">
                    (字符数:4-18之间)<span class="style4">*</span>
                </div>
            </td>
        </tr>
        <tr bgcolor="#CCCCCC">
            <td><div align="right">密码提示问题:</div></td>
            <td>
                <div align="left">
                    <input name="quiz" type="text" id="quiz" size="25" maxlength="18" <?php if(!empty($quiz)) echo "value=".$quiz;?>
                    (字符数:4-18之间,一个汉字2个字符数.)
                </div>
            </td>
        </tr>
        <tr bgcolor="#CCCCCC">
            <td><div align="right">密码回答问题:</div></td>
            <td><div align="left">
                <input name="answer" type="text" id="answer" size="25" maxlength="18" <?php if(!empty($answer)) echo "value=".$answer;?>
                (字符数:4-18之间,不要与密码提示问题相同)
            </div></td>
        </tr>
        <tr bgcolor="#CCCCCC">
            <td><div align="right">姓名:</div></td>
            <td>
                <div align="left">
                    <input name="name" type="text" id="name" size="10" maxlength="18" <?php if(!empty($name)) echo "value=".$name;?>
                    (字符数:4-18)
                </div>
            </td>
        </tr>
        <tr bgcolor="#CCCCCC">
            <td><div align="right">性别:</div></td>
            <td>
                <div align="left">
                    <input name="sex" type="radio" value="男" checked <?php if(!empty($sex)=="男") echo "value=".$sex;?>>男
                    <input type="radio" name="sex" value="女" <?php if(!empty($sex)=="女") echo "value=".$sex;?>>女
                </div>
            </td>
        </tr>
        <tr bgcolor="#CCCCCC">
            <td><div align="right">出生日期:</div></td>
            <td>
                <div align="left">
                    <select name="year" id="year">
                        <?php
                        for($year=1900;$year<=2007;$year++)
                        {
                        ?>
                        <option value="<?php echo $year;?>" <?php if($year==date('Y')) echo "selected";?>><?php echo $year;?></option>
                        <?php
                        }
                        ?>
                    </select>
                    <select name="month" id="month">
                        <?php
                        for($month=1;$month<=12;$month++)
                        {
                            if($month < 10){ $month="0".$month;}//如果$month小于10就给$month前面加一个"0"
                        ?>
                        <option value="<?php echo $month;?>" <?php if($month==date('m')) echo "selected";?>><?php echo $month;?></option>
                        <?php
                        }
                        ?>
                    </select>
                    <select name="day" id="day">
                        <?php
                        for($day=1;$day<=31;$day++)
                        {
                            if($day < 10){ $day="0".$day;}
                        ?>
                        <option value="<?php echo $day;?>" <?php if($day==date('d')) echo "selected";?>><?php echo $day;?></option>
                        <?php
                        }
                        ?>
                    </select>
                </div>
            </td>
        </tr>
        <tr bgcolor="#CCCCCC">
            <td><div align="right">QQ号:</div></td>
            <td>
                <div align="left">
                    <input name="qq" type="text" id="qq" size="25" maxlength="11" <?php if(!empty($qq)) echo "value=".$qq;?>
                </div>
            </td>
        </tr>
        <tr bgcolor="#CCCCCC">
            <td><div align="right">地区:</div></td>
            <td>
                <div align="left">
                    <input name="diqu" type="text" id="diqu" <?php if(!empty($diqu)) echo "value=".$diqu;?>
                </div>
            </td>
        </tr>
        <tr bgcolor="#CCCCCC">
            <td><div align="right">电子邮件:</div></td>
            <td>
                <div align="left">
                    <input name="email" type="text" id="email" size="25" <?php if(!empty($email)) echo "value=".$email;?>
                    (请正确填写电子邮件,注意大小写,用于密码遗失找回!)<span class="style4">*</span>
                </div>
            </td>
        </tr>
        <tr bgcolor="#CCCCCC">
            <td><div align="right">验证码:</div></td>
            <td><div align="left">
                <span class="style6">
                    <?php
                    require("verify.php");
                    $hidden_yzm = createValidate();
                    echo $hidden_yzm;
                    ?>
                    <input type="hidden" name="hidden_yzm" size="16" value="<?php echo $hidden_yzm;?>" maxlength="5"><!--将验证码值设置成隐含域的值,以便传递值-->
                </span>
            </div></td>
        </tr>
        <tr bgcolor="#CCCCCC">
            <td height="18"><div align="right">验证码:</div></td>
            <td>
                <div align="left">
                    <input name="yzm" type="text" id="yzm" size="5" maxlength="5">
                    (请按照上面显示的字母与数字输入附加码!)<span class="style4">*</span>
                </div>
            </td>
        </tr>
        <tr bgcolor="#CCCCCC">
            <td colspan="2"><div align="center">我已经阅读<a href="confer.htm" target="_blank">《网站》最终用户使用许可协议</a></div></td>
        </tr>
        <tr bgcolor="#CCCCCC">
            <td height="27" colspan="2"><div align="center">
                <input name="redio" type="radio" value="yes" checked>我同意该协议议
                <input name="redio" type="radio" value="no">我不同意该协 <span class="style4">*</span>
            </div></td>
        </tr>
        <tr bgcolor="#CCCCCC">
            <td colspan="2">
                <div align="center">
                    <input type="submit" name="submit" value="提交">
                    <input name="reset" type="reset" id="reset" value="取消">
                </div>
            </td>
        </tr>
    </table>
</form>
<?php /****************在另一个页面中插入数据,安全,快速******************/
if(!empty($_POST['submit']))//只有点击提交之后,才执行所输值的检查,所以一定要加上这一句
{
    if($error != "I\'ve found still another mistake")//如果没有任何错误
    {
        $_SESSION['userinfo']="符合条件";//就给$_SESSION['userinfo']赋上一个值,以便在另一个页面判断输入的值是否完全正确
        echo "<script language='javascript'>document.form1.action='success.php';document.form1.submit();</script>";
    }
}
?>
</body>
</html>