表单验证

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TA0003.aspx.cs" Inherits="WEB.TA0003" %>



<!DOCTYPE html>



<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title></title>

<!--                       CSS                       -->

<!-- Reset Stylesheet -->

<link rel="stylesheet" href="Resource/css/reset.css" type="text/css" media="screen" />

<!-- Main Stylesheet -->

<link rel="stylesheet" href="Resource/css/style.css" type="text/css" media="screen" />

<!-- Invalid Stylesheet. This makes stuff look pretty. Remove it if you want the CSS completely valid -->

<link rel="stylesheet" href="Resource/css/invalid.css" type="text/css" media="screen" />

<!--                       Javascripts                       -->

<!-- jQuery -->

<script type="text/javascript" src="Resource/scripts/jquery-1.8.3.min.js"></script>

<!-- jQuery Configuration -->

<script type="text/javascript" src="Resource/scripts/simpla.jquery.configuration.js"></script>

<!-- Facebox jQuery Plugin -->

<script type="text/javascript" src="Resource/scripts/facebox.js"></script>

<!-- jQuery WYSIWYG Plugin -->

<script type="text/javascript" src="Resource/scripts/jquery.wysiwyg.js"></script>

<!-- jQuery Datepicker Plugin -->

<script type="text/javascript" src="Resource/scripts/jquery.provincesCity.js"></script>

<script type="text/javascript" src="Resource/scripts/personjs.js"></script>

<script type="text/javascript" src="Resource/scripts/ajax.js"></script>

<!--  日历样式和JS -->

<link rel="stylesheet" href="Resource/css/jqueryui.css" type="text/css" media="screen" />

<script type="text/javascript" src="Resource/scripts/jquery.ui.js"></script>

<script src="Resource/scripts/formValidator-4.0.1.js" type="text/javascript" charset="UTF-8"></script>

<script src="Resource/scripts/formValidatorRegex.js" type="text/javascript" charset="UTF-8"></script>

    <script type="text/javascript">

        //验证

        $(function () {

            $("#check_thishtml .text-input").live("blur", function () {

                if ($(this).val() == "") {

                    $(this).parent().find(".msg").removeClass("input-notification success png_bg");

                    $(this).parent().find(".msg").addClass("input-notification error png_bg");

                    $(this).parent().find(".msg").html("内容不能为空!");

                }

                else {

                    if ($(this).attr("id") == "txtPhone") {

                        var strPhone = $(this).val();

                        var phoneRegWithArea = /^0{0,1}(13[0-9]|15[0-9]|18[0-9])[0-9]{8}$/;

                        if (strPhone.length == 11) {

                            if (phoneRegWithArea.test(strPhone)) {

                                $(this).parent().find(".msg").removeClass("input-notification error png_bg");

                                $(this).parent().find(".msg").addClass("input-notification success png_bg");

                                $(this).parent().find(".msg").html("通过信息验证!");

                            } else {

                                $(this).parent().find(".msg").removeClass("input-notification success png_bg");

                                $(this).parent().find(".msg").addClass("input-notification error png_bg");

                                $(this).parent().find(".msg").html("手机号码的格式填写错误!");

                            }

                        } else {

                            $(this).parent().find(".msg").removeClass("input-notification success png_bg");

                            $(this).parent().find(".msg").addClass("input-notification error png_bg");

                            $(this).parent().find(".msg").html("手机号码的格式填写错误!");

                        }

                    }

                    else if ($(this).attr("id") == "txtName") {

                        var strName = $(this).val().length;

                        var nameRegWithArea = /^[\u4e00-\u9fa5]{0,}$/;

                        if (nameRegWithArea.test(strTel)) {

                            if (strName > 16) {

                                $(this).parent().find(".msg").removeClass("input-notification success png_bg");

                                $(this).parent().find(".msg").addClass("input-notification error png_bg");

                                $(this).parent().find(".msg").html("内容超长!");

                            } else {

                                $(this).parent().find(".msg").removeClass("input-notification error png_bg");

                                $(this).parent().find(".msg").addClass("input-notification success png_bg");

                                $(this).parent().find(".msg").html("通过信息验证!");

                            }

                        } else {

                            $(this).parent().find(".msg").removeClass("input-notification success png_bg");

                            $(this).parent().find(".msg").addClass("input-notification error png_bg");

                            $(this).parent().find(".msg").html("姓名必须为中文!");

                        }

                    }

                    else if ($(this).attr("id") == "txtTel") {

                        var strTel = $(this).val();

                        var telRegWithArea = /\d{3}-\d{8}|\d{4}-\d{7}/;

                        if (telRegWithArea.test(strTel)) {

                            $(this).parent().find(".msg").removeClass("input-notification error png_bg");

                            $(this).parent().find(".msg").addClass("input-notification success png_bg");

                            $(this).parent().find(".msg").html("通过信息验证!");

                        } else {

                            $(this).parent().find(".msg").removeClass("input-notification success png_bg");

                            $(this).parent().find(".msg").addClass("input-notification error png_bg");

                            $(this).parent().find(".msg").html("电话号码的格式填写错误,例:021-88668866!");

                        }

                    }

                    else if ($(this).attr("id") == "txtMail") {

                        var strTel = $(this).val();

                        var mailRegWithArea = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;

                        if (mailRegWithArea.test(strTel)) {

                            $(this).parent().find(".msg").removeClass("input-notification error png_bg");

                            $(this).parent().find(".msg").addClass("input-notification success png_bg");

                            $(this).parent().find(".msg").html("通过信息验证!");

                        } else {

                            $(this).parent().find(".msg").removeClass("input-notification success png_bg");

                            $(this).parent().find(".msg").addClass("input-notification error png_bg");

                            $(this).parent().find(".msg").html("邮件格式错误!");

                        }

                    }

                    else if ($(this).attr("id") == "txtQq") {

                        var strTel = $(this).val();

                        var qqRegWithArea = /[1-9][0-9]{4,}/;

                        if (qqRegWithArea.test(strTel)) {

                            $(this).parent().find(".msg").removeClass("input-notification error png_bg");

                            $(this).parent().find(".msg").addClass("input-notification success png_bg");

                            $(this).parent().find(".msg").html("通过信息验证!");

                        } else {

                            $(this).parent().find(".msg").removeClass("input-notification success png_bg");

                            $(this).parent().find(".msg").addClass("input-notification error png_bg");

                            $(this).parent().find(".msg").html("QQ格式错误!");

                        }

                    }

                    else if ($(this).attr("id") == "txtOldPassWord") {

                        obj = $(this).parent();

                        $.ajax({

                            type: "Post",

                            url: "TA0003.aspx/CheckPassWord",

                            data: "{'passWord':'" + $(this).val() +"'}",

                            contentType: "application/json; charset=utf-8",

                            dataType: "json",

                            success: function (data) {

                                if (data.d != "") {

                                    if (data.d == "正确") {

                                        obj.find(".msg").removeClass("input-notification error png_bg");

                                        obj.find(".msg").addClass("input-notification success png_bg");

                                        obj.find(".msg").html("通过信息验证!");

                                    }

                                    else {

                                        obj.find(".msg").removeClass("input-notification success png_bg");

                                        obj.find(".msg").addClass("input-notification error png_bg");

                                        obj.find(".msg").html("密码填写错误!");

                                    }

                                }

                                else {

                                    obj.find(".msg").removeClass("input-notification success png_bg");

                                    obj.find(".msg").addClass("input-notification error png_bg");

                                    obj.find(".msg").html("密码填写错误!");

                                }

                            },

                            error: function () {

                                $(this).parent().find(".msg").removeClass("input-notification success png_bg");

                                $(this).parent().find(".msg").addClass("input-notification error png_bg");

                                $(this).parent().find(".msg").html("您两次输入的账号密码不一致!");

                            }

                        });                       

                    }

                    else if ($(this).attr("id") == "txtNewPassWordAgain") {

                        if ($(this).val() == $("#txtNewPassWord").val()) {

                            $(this).parent().find(".msg").removeClass("input-notification error png_bg");

                            $(this).parent().find(".msg").addClass("input-notification success png_bg");

                            $(this).parent().find(".msg").html("通过信息验证!");

                        }

                        else {

                            $(this).parent().find(".msg").removeClass("input-notification success png_bg");

                            $(this).parent().find(".msg").addClass("input-notification error png_bg");

                            $(this).parent().find(".msg").html("您两次输入的账号密码不一致!");

                        }

                    }

                    else {

                        $(this).parent().find(".msg").removeClass("input-notification error png_bg");

                        $(this).parent().find(".msg").addClass("input-notification success png_bg");

                        $(this).parent().find(".msg").html("通过信息验证!");

                    }

                }

            })

        });

    </script>

</head>

<body>

    <form id="form1" runat="server">

        <div id="main-content">

            <div class="content-box"> 

                <!-- Start Content Box -->

                <div class="content-box-header">

                            <h3>个人信息</h3>

                <ul class="content-box-tabs">

                    <li><a href="#tab1" class="default-tab">个人信息</a></li>

                    <li><a href="#tab2">密码修改</a></li>

                    <li><a href="#tab3">个人头像</a></li>

                </ul>



                <div class="clear"></div>

                </div>

                <!-- End .content-box-header -->

                <div class="content-box-content" id="check_thishtml"> 

                    <!--个人信息开始-->

                    <div class="tab-content default-tab" id="tab1">         

                        <p>

                            <span class="form_tit">用户名:</span>

                            <span id="spName" runat="server">ceshi</span>

                        </p>

                        <p>

                            <span class="form_tit">真实姓名:</span>

                            <asp:TextBox ID="txtName" runat="server" CssClass="text-input" Width="200px" onblur="Verify(this)"></asp:TextBox>

                            <span class="msg"></span>

                        </p>

                        <p class="fl">

                            <span class="form_tit">性别:</span>

                            <asp:RadioButtonList ID="rdoSex" runat="server" RepeatDirection="Horizontal" Width="150px" CssClass="fl">

                                <asp:ListItem Value="0"></asp:ListItem>

                                <asp:ListItem Value="1"></asp:ListItem>

                            </asp:RadioButtonList>

                        </p>

                        <div class="clear"></div>

                        <p>

                            <span class="form_tit">手机号码:</span>

                            <asp:TextBox ID="txtPhone" runat="server" CssClass="text-input" Width="200px"></asp:TextBox>

                            <span class="msg"></span>

                        </p>

                        <p>

                            <span class="form_tit">电话号码:</span>

                            <asp:TextBox ID="txtTel" runat="server" CssClass="text-input" Width="200px"></asp:TextBox>

                            <span class="msg"></span>

                        </p>

                        <p>

                            <span class="form_tit">传真号码:</span>

                            <asp:TextBox ID="txtFax" runat="server" CssClass="text-input" Width="200px"></asp:TextBox>

                            <span class="msg"></span>

                        </p>

                        <p>

                            <span class="form_tit">邮箱地址:</span>

                            <asp:TextBox ID="txtMail" runat="server" CssClass="text-input" Width="200px"></asp:TextBox>

                            <span class="msg"></span>

                        </p>

                        <p>

                            <span class="form_tit">QQ号码:</span>

                            <asp:TextBox ID="txtQq" runat="server" CssClass="text-input" Width="200px"></asp:TextBox>

                            <span class="msg"></span>

                        </p>

                        <p>

                             <span class="form_tit"></span>

                            <asp:Button id="btnSave" class="button" runat="server" text="保存修改" OnClick="btnSave_Click"/>

                        </p>        

                    </div>

                    <!-- 个人信息结束 --> 

                    <!-- 修改密码开始 -->

                    <div class="tab-content" id="tab2">

                        <p>

                            <span class="form_tit">原密码:</span>

                            <asp:TextBox ID="txtOldPassWord" runat="server" CssClass="text-input" Width="200px" TextMode="Password"></asp:TextBox>

                            <span class="msg"></span>

                        </p>

                        <p>

                            <span class="form_tit">新密码:</span>

                            <asp:TextBox ID="txtNewPassWord" runat="server" CssClass="text-input" Width="200px" TextMode="Password"></asp:TextBox>

                            <span class="msg"></span>

                        </p>

                        <p>

                            <span class="form_tit">确认新密码:</span>

                            <asp:TextBox ID="txtNewPassWordAgain" runat="server" CssClass="text-input" Width="200px" TextMode="Password"></asp:TextBox>

                            <span class="msg"></span>

                        </p>

                        <p>

                             <span class="form_tit"></span>

                            <asp:Button id="btnSavePassWord" class="button" runat="server" text="保存修改" OnClick="btnSavePassWord_Click"/>

                        </p>

         

                    </div>

                    <!-- 修改密码结束 --> 

                    <!-- 个人头像开始 -->

                    <div class="tab-content" id="tab3">

                        个人头像

         

                    </div>

                    <!-- 个人头像结束 --> 

                </div>

            </div>

        </div>

    </form>

</body>

</html>

 

你可能感兴趣的:(表单验证)