php用户注册页面利用js进行表单验证具体实例


Posted in PHP onOctober 17, 2013
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
    <head> 
        <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />  
        <title>用户注册 - 三水点靠木</title> 
        <link href="../css/login.css" rel="stylesheet" type="text/css" /> 
        <link href="../css/page_bottom.css" rel="stylesheet" type="text/css" /> 
        <script type="text/javascript" src="../js/jquery-1.7.1.js"></script> 
        <script type="text/javascript"> 
            var flag = { 
                "email":false, 
                "nickname":false, 
                "password":false, 
                "verify":false 
            };             $(function(){ 
                $("#txtEmail").blur(function () { 
                                        var email=$(this).val(); 
                                        //alert(email); 
                                        if(email==""){ 
                                            $("#email\\.info").html("Email地址不能为空"); 
                                            return; 
                                        } 
                                        var pattern=/\b(^['_A-Za-z0-9-]+(\.['_A-Za-z0-9-]+)*@([A-Za-z0-9-])+(\.[A-Za-z0-9-]+)*((\.[A-Za-z0-9]{2,})|(\.[A-Za-z0-9]{2,}\.[A-Za-z0-9]{2,}))$)\b/; 
                                        if(!pattern.test(email)){ 
                                            $("#email\\.info").html("Email格式不正确"); 
                                            return; 
                                        } 
                                        $.get("check_email.php?email="+email,null, 
                                            function(data){ 
                                                $("#email\\.info").html(data); 
                                                if (data=="可以注册") { 
                                                    flag.email=true; 
                                                } 
                                            } 
                                        ); 
                                    }); 
                $("#txtNickName").blur(function () { 
                                            var nickname=$(this).val(); 
                                            if(nickname==""){ 
                                                $("#name\\.info").html("昵称不能为空"); 
                                                return; 
                                            } 
                                            var pattern = /\b(^['A-Za-z0-9]{4,20}$)\b/; 
                                            if (!pattern.test(nickname)) { 
                                                $("#name\\.info").html("昵称格式不正确"); 
                                                return; 
                                            }else{ 
                                                $("#name\\.info").html("昵称格式正确"); 
                                                flag.nickname=true; 
                                                return; 
                                            } 
                                       }); 
                $("#txtPassword").blur(function () { 
                                            var password=$(this).val(); 
                                            if (password=="") { 
                                                $("#password\\.info").html("密码不能为空"); 
                                                return; 
                                            } 
                                            var pattern = /\b(^['A-Za-z0-9]{4,20}$)\b/; 
                                            if (!pattern.test(password)) { 
                                                $("#password\\.info").html("密码格式不正确"); 
                                                return;    
                                            }else{ 
                                                $("#password\\.info").html("密码格式正确"); 
                                                //flag.password=true; 
                                                return; 
                                            } 
                                       }); 
                $("#txtRepeatPass").blur(function () { 
                                            var password1=$(this).val(); 
                                            if (password1=="") { 
                                                $("#password1\\.info").html("密码不能为空"); 
                                                return; 
                                            } 
                                            var pattern = /\b(^['A-Za-z0-9]{4,20}$)\b/; 
                                            if (!pattern.test(password1)) { 
                                                $("#password1\\.info").html("密码格式不正确"); 
                                                return;    
                                            }else if(password1!=$("#txtPassword").val()){ 
                                                $("#password1\\.info").html("两次输入的密码不一致"); 
                                                return; 
                                            }else{ 
                                                $("#password1\\.info").html("重复密码正确"); 
                                                flag.password=true; 
                                                return; 
                                            }                                             
                                        }); 
                $("#txtVerifyCode").blur(function () { 
                                            var verify=$(this).val(); 
                                            if(verify==""){ 
                                                $("#number\\.info").html("验证码不能为空"); 
                                                return; 
                                            } 
                                            $.post("./verify/check.php",{verify:verify}, 
                                                function(data){ 
                                                    $("#number\\.info").html(data); 
                                                    if (data=="验证成功") { 
                                                        flag.verify=true; 
                                                    } 
                                                } 
                                            ); 
                                         }) 
                $("#f").submit(function(){ 
                                    var ok = flag.email&&flag.password&&flag.verify&&flag.nickname; 
                                    if(ok==false){ 
                                        alert("表单项正在检测或存在错误"); 
                                        history.back(); 
                                        return false; 
                                    } 
                                    return true; 
                                });  
            }) 
        </script> 
    </head> 
    <body> 
        <?php include("../common/head.php"); ?> 
        <div class="login_step"> 
            注册步骤:<span class="red_bold">1.填写信息</span> > 2.验证邮箱 > 3.注册成功 
        </div> 
        <div class="fill_message"> 
            <form name="ctl00" method="post" action="save_reg.php" id="f"> 
                <h2>以下均为必填项</h2> 
                <table class="tab_login" > 
                    <tr> 
                        <td valign="top" class="w1">请填写您的Email地址:</td> 
                        <td> 
                            <input name="email" type="text" id="txtEmail" class="text_input"/> 
                            <div class="text_left" id="emailValidMsg"> 
                                <p>请填写有效的Email地址。</p> 
                                <span id="email.info" style="color:red"></span> 
                            </div> 
                        </td> 
                    </tr> 
                    <tr> 
                        <td valign="top" class="w1">设置您在三水点靠木的昵称:</td> 
                        <td> 
                            <input name="nickname" type="text" id="txtNickName" class="text_input" /> 
                            <div class="text_left" id="nickNameValidMsg"> 
                                <p>由小写英文字母、中文、数字组成,长度4-20个字符,一个汉字为两个字符。</p> 
                                <span id="name.info" style="color:red"></span> 
                            </div> 
                        </td> 
                    </tr> 
                    <tr> 
                        <td valign="top" class="w1">设置密码:</td> 
                        <td> 
                            <input name="password" type="password" id="txtPassword" class="text_input" /> 
                            <div class="text_left" id="passwordValidMsg"> 
                                <p>您的密码可以由大小写英文字母、数字组成,长度6-20位。</p> 
                                <span id="password.info" style="color:red"></span> 
                            </div> 
                        </td> 
                    </tr> 
                    <tr> 
                        <td valign="top" class="w1">再次输入您设置的密码:</td> 
                        <td> 
                            <input name="password1" type="password" id="txtRepeatPass" class="text_input"/> 
                            <div class="text_left" id="repeatPassValidMsg"> 
                            <span id="password1.info" style="color:red"></span> 
                            </div> 
                        </td> 
                    </tr> 
                    <tr> 
                        <td valign="top" class="w1">验证码:</td> 
                        <td> 
                            <img class="yzm_img" id='imgVcode' src='./verify/verify.php' style="cursor:pointer" border='0' onclick="document.getElementById('imgVcode').src='./verify/verify.php?t='+Math.random()"/> 
                            <input name="number" type="text" id="txtVerifyCode" class="yzm_input"/> 
                            <div class="text_left t1"> 
                                <p class="t1"> 
                                    <span id="vcodeValidMsg">请输入图片中的四个字母。</span>                                     
                                    <a href="#" style="cursor:pointer" onclick="document.getElementById('imgVcode').src='./verify/verify.php?t='+Math.random()">看不清楚?换个图片</a> 
                                    <br /> 
                                    <span id="number.info" style="color:red"></span> 
                                </p> 
                            </div> 
                        </td> 
                    </tr> 
                </table> 
                <div class="login_in"> 
                    <input id="btnClientRegister" class="button_1" name="submit" type="submit" value="注 册"/> 
                </div> 
            </form> 
        </div> 
        <?php include("../common/foot.php"); ?> 
    </body> 
</html>
PHP 相关文章推荐
判“新”函数:得到今天与明天的秒数
Oct 09 PHP
PHP 选项及相关信息函数库
Dec 04 PHP
Dedecms常用函数解析
Feb 01 PHP
php自动获取字符串编码函数mb_detect_encoding
May 31 PHP
ThinkPHP连接数据库的方式汇总
Dec 05 PHP
利用PHP自动生成印有用户信息的名片
Aug 01 PHP
php从数据库中读取特定的行(实例)
Jun 02 PHP
PHP观察者模式原理与简单实现方法示例
Aug 25 PHP
PHP设计模式之单例模式原理与实现方法分析
Apr 25 PHP
PHP删除数组中指定值的元素常用方法实例分析【4种方法】
Aug 21 PHP
PHP实现微信申请退款功能
Oct 01 PHP
Yii 框架使用Forms操作详解
May 18 PHP
10 个经典PHP函数
Oct 17 #PHP
php中怎么搜索相关联数组键值及获取之
Oct 17 #PHP
php class类的用法详细总结
Oct 17 #PHP
div li的多行多列 无刷新分页示例代码
Oct 16 #PHP
无刷新动态加载数据 滚动条加载适合评论等页面
Oct 16 #PHP
PHP字符串长度计算 - strlen()函数使用介绍
Oct 15 #PHP
php后台如何避免用户直接进入方法实例
Oct 15 #PHP
You might like
PHP 模板高级篇总结
2006/12/21 PHP
Yii2中SqlDataProvider用法示例
2016/09/22 PHP
jQuery 研究心得 取得属性的值
2007/11/30 Javascript
精通JavaScript 纠正 cleanWhitespace函数
2010/03/11 Javascript
HTML中的setCapture和releaseCapture使用介绍
2012/03/21 Javascript
一行代码告别document.getElementById
2012/06/01 Javascript
基于jQuery中对数组进行操作的方法
2013/04/16 Javascript
jQuery ReferenceError: $ is not defined 错误的处理办法
2013/05/10 Javascript
jQuery打印图片pdf、txt示例代码
2014/07/22 Javascript
javascript比较两个日期相差天数的方法
2015/07/23 Javascript
js实现音频控制进度条功能
2017/04/01 Javascript
Vue实现动态响应数据变化
2017/04/28 Javascript
vue多种弹框的弹出形式的示例代码
2017/09/18 Javascript
JS设计模式之数据访问对象模式的实例讲解
2017/09/30 Javascript
微信小程序promsie.all和promise顺序执行
2017/10/27 Javascript
vuejs element table 表格添加行,修改,单独删除行,批量删除行操作
2020/07/18 Javascript
python中类的一些方法分析
2014/09/25 Python
Python中列表元素转为数字的方法分析
2016/06/14 Python
Python使用正则表达式实现文本替换的方法
2017/04/18 Python
Python3 操作符重载方法示例
2017/11/23 Python
python 利用for循环 保存多个图像或者文件的实例
2018/11/09 Python
python多进程并发demo实例解析
2019/12/13 Python
windows下python安装pip方法详解
2020/02/10 Python
Python控制鼠标键盘代码实例
2020/12/08 Python
HTML5新增属性data-*和js/jquery之间的交互及注意事项
2017/08/08 HTML / CSS
Shein英国:女性时尚网上商店
2019/04/10 全球购物
荷兰的时尚市场:To Be Dressed
2019/05/06 全球购物
土地转让协议书
2014/04/15 职场文书
合伙协议书范本
2014/04/21 职场文书
挂牌仪式策划方案
2014/05/18 职场文书
旅游文化节策划方案
2014/06/06 职场文书
幼儿园教师节感谢信
2015/01/23 职场文书
护士自荐信怎么写
2015/03/06 职场文书
手把手教你从零开始react+antd搭建项目
2021/06/03 Javascript
游戏《东方异文石:爱亚利亚黎明》正式版发布
2022/04/03 其他游戏
Alexa停服!网站排名将何去何从?目前还没有替代品。
2022/04/15 杂记