js动态验证用户注册


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Register.aspx.cs" Inherits="WebPage_Users_Register" MasterPageFile="~/Include/WebMaster.master" Title="HEZHONG GLOBAL——Register"%>
<asp:Content ID="Content1" ContentPlaceHolderID="WebContent" runat="server">
<script type="text/javascript">
var error = 0;
function checkText(objID)
{
var obj = objID;
if(obj.value != "")
{
switch(obj.id)
{
case "ctl00_WebContent_txtUserName":
if(/^[a-zA-Z][a-zA-Z0-9_]{3,15}$/gi.test(obj.value))
{
document.getElementById("divBlanktxtUserName").style.display = "none";
// document.getElementById("divInfotxtUserName").style.display = "block";
// //document.getElementById("divRighttxtUserName").style.display = "block";
document.getElementById("divErrortxtUserName").style.display = "none";
document.getElementById("ctl00_WebContent_lblAlert").style.display = "block";
error = 0;
}
else
{
document.getElementById("divBlanktxtUserName").style.display = "none";
// document.getElementById("divInfotxtUserName").style.display = "block";
// //document.getElementById("divRighttxtUserName").style.display = "none";
document.getElementById("divErrortxtUserName").style.display = "block";
document.getElementById("ctl00_WebContent_lblAlert").style.display = "none";
error = 1;
}
break;
case "ctl00_WebContent_txtPassword":
if(obj.value.length >= 6 && obj.value.length <= 16 && obj.value.indexOf(" ") == -1)
{
document.getElementById("divBlanktxtPassword").style.display = "none";
document.getElementById("divInfotxtPassword").style.display = "none";
document.getElementById("divRighttxtPassword").style.display = "block";
document.getElementById("divErrortxtPassword").style.display = "none";
error = 0;
}
else
{
document.getElementById("divBlanktxtPassword").style.display = "none";
document.getElementById("divInfotxtPassword").style.display = "none";
document.getElementById("divRighttxtPassword").style.display = "none";
document.getElementById("divErrortxtPassword").style.display = "block";
error = 1;
}
break;
case "ctl00_WebContent_txtConfirmPwd":
if(obj.value == document.getElementById("<%=txtPassword.ClientID %>").value)
{
document.getElementById("divInfotxtConfirmPwd").style.display = "none";
document.getElementById("divRighttxtConfirmPwd").style.display = "block";
document.getElementById("divErrortxtConfirmPwd").style.display = "none";
error = 0;
}
else
{
document.getElementById("divInfotxtConfirmPwd").style.display = "none";
document.getElementById("divRighttxtConfirmPwd").style.display = "none";
document.getElementById("divErrortxtConfirmPwd").style.display = "block";
error = 1;
}
break;
case "ctl00_WebContent_txtQuestion":
if(obj.value.length >= 4 && obj.value.length <=30)
{
document.getElementById("divBlanktxtQuestion").style.display = "none";
document.getElementById("divInfotxtQuestion").style.display = "none";
document.getElementById("divRighttxtQuestion").style.display = "block";
document.getElementById("divErrortxtQuestion").style.display = "none";
error = 0;
}
else
{
document.getElementById("divBlanktxtQuestion").style.display = "none";
document.getElementById("divInfotxtQuestion").style.display = "none";
document.getElementById("divRighttxtQuestion").style.display = "none";
document.getElementById("divErrortxtQuestion").style.display = "block";
error = 1;
}
break;
case "ctl00_WebContent_txtAnswer":
if(obj.value.length >= 4 && obj.value.length <=30)
{
document.getElementById("divBlanktxtAnswer").style.display = "none";
document.getElementById("divRighttxtAnswer").style.display = "block";
document.getElementById("divErrortxtAnswer").style.display = "none";
error = 0;
}
else
{
document.getElementById("divBlanktxtAnswer").style.display = "none";
document.getElementById("divRighttxtAnswer").style.display = "none";
document.getElementById("divErrortxtAnswer").style.display = "block";
error = 1;
}
break;
case "ctl00_WebContent_txtCompany":
if(obj.value.length <=200)
{
document.getElementById("divBlanktxtCompany").style.display = "none";
document.getElementById("divRighttxtCompany").style.display = "block";
document.getElementById("divErrortxtCompany").style.display = "none";
error = 0;
}
else
{
document.getElementById("divBlanktxtCompany").style.display = "none";
document.getElementById("divRighttxtCompany").style.display = "none";
document.getElementById("divErrortxtCompany").style.display = "block";
error = 1;
}
break;
case "ctl00_WebContent_txtRealName":
if(obj.value.length <=200)
{
document.getElementById("divBlanktxtRealName").style.display = "none";
document.getElementById("divRighttxtRealName").style.display = "block";
document.getElementById("divErrortxtRealName").style.display = "none";
error = 0;
}
else
{
document.getElementById("divBlanktxtRealName").style.display = "none";
document.getElementById("divRighttxtRealName").style.display = "none";
document.getElementById("divErrortxtRealName").style.display = "block";
error = 1;
}
break;
case "ctl00_WebContent_txtAddress":
if(obj.value.length <=200)
{
document.getElementById("divRighttxtAddress").style.display = "block";
document.getElementById("divErrortxtAddress").style.display = "none";
error = 0;
}
else
{
document.getElementById("divRighttxtAddress").style.display = "none";
document.getElementById("divErrortxtAddress").style.display = "block";
error = 1;
}
break;
case "ctl00_WebContent_txtTel":
if(/^(([0\+]\d{2,3}-)?(0\d{2,3})-)(\d{7,8})(-(\d{3,}))?$/.test(obj.value))
{
//document.getElementById("divInfotxtTel").style.display = "none";
document.getElementById("divBlanktxtTel").style.display = "none";
document.getElementById("divRighttxtTel").style.display = "block";
document.getElementById("divErrortxtTel").style.display = "none";
error = 0;
}
else
{
// document.getElementById("divInfotxtTel").style.display = "none";
document.getElementById("divBlanktxtTel").style.display = "none";
document.getElementById("divRighttxtTel").style.display = "none";
document.getElementById("divErrortxtTel").style.display = "block";
error = 1;
}
break;
case "ctl00_WebContent_txtFax":
if(/^(([0\+]\d{2,3}-)?(0\d{2,3})-)(\d{7,8})(-(\d{3,}))?$/.test(obj.value))
{
//document.getElementById("divInfotxtFax").style.display = "none";
document.getElementById("divRighttxtFax").style.display = "block";
document.getElementById("divErrortxtFax").style.display = "none";
error = 0;
}
else
{
//document.getElementById("divInfotxtFax").style.display = "none";
document.getElementById("divRighttxtFax").style.display = "none";
document.getElementById("divErrortxtFax").style.display = "block";
error = 1;
}
break;
case "ctl00_WebContent_txtEmail":
if(/^([a-zA-Z0-9]+[_|\-|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\-|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/gi.test(obj.value))
{
document.getElementById("divBlanktxtEmail").style.display = "none";
document.getElementById("divInfotxtEmail").style.display = "none";
document.getElementById("divRighttxtEmail").style.display = "block";
document.getElementById("divErrortxtEmail").style.display = "none";
error = 0;
}
else
{
document.getElementById("divBlanktxtEmail").style.display = "none";
document.getElementById("divInfotxtEmail").style.display = "none";
document.getElementById("divRighttxtEmail").style.display = "none";
document.getElementById("divErrortxtEmail").style.display = "block";
error = 1;
}
break;
case "ctl00_WebContent_txtPostAddress":
if(obj.value.length <= 300)
{
document.getElementById("divRighttxtPostAddress").style.display = "block";
document.getElementById("divErrortxtPostAddress").style.display = "none";
error = 0;
}
else
{
document.getElementById("divRighttxtPostAddress").style.display = "none";
document.getElementById("divErrortxtPostAddress").style.display = "block";
error = 1;
}
break;
case "ctl00_WebContent_txtWebSite":
if(obj.value.length <= 100)
{
document.getElementById("divRighttxtWebSite").style.display = "block";
document.getElementById("divErrortxtWebSite").style.display = "none";
error = 0;
}
else
{
document.getElementById("divRighttxtWebSite").style.display = "none";
document.getElementById("divErrortxtWebSite").style.display = "block";
error = 1;
}
break;
}
}
else
{
switch(obj.id)
{
case "ctl00_WebContent_txtUserName":
document.getElementById("divBlanktxtUserName").style.display = "block";
// document.getElementById("divInfotxtUserName").style.display = "block";
// //document.getElementById("divRighttxtUserName").style.display = "none";
document.getElementById("divErrortxtUserName").style.display = "none";
document.getElementById("ctl00_WebContent_lblAlert").style.display = "none";
error = 1;
break;
case "ctl00_WebContent_txtPassword":
document.getElementById("divBlanktxtPassword").style.display = "block";
document.getElementById("divInfotxtPassword").style.display = "none";
document.getElementById("divRighttxtPassword").style.display = "none";
document.getElementById("divErrortxtPassword").style.display = "none";
error = 1;
break;
case "ctl00_WebContent_txtConfirmPwd":
document.getElementById("divInfotxtConfirmPwd").style.display = "block";
document.getElementById("divRighttxtConfirmPwd").style.display = "none";
document.getElementById("divErrortxtConfirmPwd").style.display = "none";
break;
case "ctl00_WebContent_txtQuestion":
document.getElementById("divBlanktxtQuestion").style.display = "block";
document.getElementById("divInfotxtQuestion").style.display = "none";
document.getElementById("divRighttxtQuestion").style.display = "none";
document.getElementById("divErrortxtQuestion").style.display = "none";
error = 1;
break;
case "ctl00_WebContent_txtAnswer":
document.getElementById("divBlanktxtAnswer").style.display = "block";
document.getElementById("divRighttxtAnswer").style.display = "none";
document.getElementById("divErrortxtAnswer").style.display = "none";
error = 1;
break;
case "ctl00_WebContent_txtCompany":
document.getElementById("divBlanktxtCompany").style.display = "block";
document.getElementById("divRighttxtCompany").style.display = "none";
document.getElementById("divErrortxtCompany").style.display = "none";
error = 1;
break;
case "ctl00_WebContent_txtRealName":
document.getElementById("divBlanktxtRealName").style.display = "block";
document.getElementById("divRighttxtRealName").style.display = "none";
document.getElementById("divErrortxtRealName").style.display = "none";
error = 1;
break;
case "ctl00_WebContent_txtAddress":
document.getElementById("divRighttxtAddress").style.display = "none";
document.getElementById("divErrortxtAddress").style.display = "none";
break;
case "ctl00_WebContent_txtTel":
//document.getElementById("divInfotxtTel").style.display = "block";
document.getElementById("divBlanktxtTel").style.display = "block";
document.getElementById("divRighttxtTel").style.display = "none";
document.getElementById("divErrortxtTel").style.display = "none";
error = 1;
break;
case "ctl00_WebContent_txtFax":
//document.getElementById("divInfotxtFax").style.display = "block";
document.getElementById("divRighttxtFax").style.display = "none";
document.getElementById("divErrortxtFax").style.display = "none";
break;
case "ctl00_WebContent_txtEmail":
document.getElementById("divBlanktxtEmail").style.display = "block";
document.getElementById("divInfotxtEmail").style.display = "none";
document.getElementById("divRighttxtEmail").style.display = "none";
document.getElementById("divErrortxtEmail").style.display = "none";
error = 1;
break;
case "ctl00_WebContent_txtPostAddress":
document.getElementById("divRighttxtPostAddress").style.display = "none";
document.getElementById("divErrortxtPostAddress").style.display = "none";
break;
case "ctl00_WebContent_txtWebSite":
document.getElementById("divRighttxtWebSite").style.display = "none";
document.getElementById("divErrortxtWebSite").style.display = "none";
break;
}
}
}
function ConfirmText()
{
error=0;
checkText(document.getElementById("ContentTable").getElementsByTagName("input")[0]);
if(error == 1)
{
return false;
}
else
{
return true;
}
}
function OnSubmitCheck(){
var num=document.getElementById("ContentTable").getElementsByTagName("input").length;
for (var i=0;i<num;i++){
checkText(document.getElementById("ContentTable").getElementsByTagName("input")[i]);
}
if(error == 1)
{
return false;
}
else
{
return true;
}
}
function Check()
{
var e = document.getElementById('Checkbox1');
if(e.checked == true)
{
document.getElementById('othertable').style.display ="block";
}
else
{
document.getElementById('othertable').style.display ="none";
}
}
</script>
<div style="padding:10px;">
<table width="100%" style="text-align:left;" id="ContentTable" cellpadding="0" cellspacing="0">
<tr>
<td style="width: 135px" class="Registerlefttd"><span style="color:Red">*</span>用 户 名:</td>
<td style="width: 420px" class="Registertd">
<asp:TextBox ID="txtUserName" runat="server" onBlur="checkText(this);"></asp:TextBox>
<asp:Button ID="btnCheckName" runat="server" Text="检查用户名是否可用" OnClick="btnCheckName_Click" OnClientClick="return ConfirmText();"/></td>
<td class="Registertd" style="width: 420px">
<span id="divInfotxtUserName" style="display:block" class="Registermsg">字母、数字、下划线的组合,不区分大小写,4-16个字符,不能有汉字</span>
<span id="divBlanktxtUserName" style="display:none" class="RegisterErrormsg">请输入用户名!</span>
<%--<div id="divRighttxtUserName" style="display:none" class="RegisterRightmsg">成功</div>--%>
<span id="divErrortxtUserName" style="display:none" class="RegisterErrormsg">注册用户名不符合要求</span>
<asp:Label ID="lblAlert" runat="server" Text=""></asp:Label>
</td>
</tr>
<tr>
<td style="width: 135px" class="Registerlefttd">
<span style="color:Red">*</span>密 码:
</td>
<td style="width: 420px" class="Registertd">
<asp:TextBox ID="txtPassword" runat="server" onBlur="checkText(this);" TextMode="Password"></asp:TextBox>
</td>
<td class="Registertd">
<span id="divInfotxtPassword" style="display:block" class="Registermsg">6-16个非空白字符,区分英文大小写</span>
<span id="divBlanktxtPassword" style="display:none" class="RegisterErrormsg">请输入密码!</span>
<span id="divRighttxtPassword" style="display:none" class="RegisterRightmsg">成功</span>
<span id="divErrortxtPassword" style="display:none" class="RegisterErrormsg">密码不符合要求(请确认长度在6-16个非空白字符)</span>
</td>
</tr>
<tr>
<td style="width: 135px" class="Registerlefttd">
<span style="color:Red">*</span>确认密码:
</td>
<td style="width: 420px" class="Registertd">
<asp:TextBox ID="txtConfirmPwd" runat="server" onBlur="checkText(this);" TextMode="Password"></asp:TextBox>
</td>
<td class="Registertd">
<span id="divInfotxtConfirmPwd" style="display:block" class="Registermsg">重复输入一次密码</span>
<span id="divRighttxtConfirmPwd" style="display:none" class="RegisterRightmsg">成功</span>
<span id="divErrortxtConfirmPwd" style="display:none" class="RegisterErrormsg">您2次输入的密码不相同</span>
</td>
</tr>
<tr>
<td style="width: 135px" class="Registerlefttd">
<span style="color:Red">*</span> 找回密码问题:
</td>
<td style="width: 420px" class="Registertd">
<asp:TextBox ID="txtQuestion" runat="server" onBlur="checkText(this);" Width="400"></asp:TextBox>
</td>
<td class="Registertd">
<span id="divInfotxtQuestion" style="display:block" class="Registermsg">密码忘记时可根据此问题找回密码</span>
<span id="divBlanktxtQuestion" style="display:none" class="RegisterErrormsg">请输入找回密码问题!</span>
<span id="divRighttxtQuestion" style="display:none" class="RegisterRightmsg">成功</span>
<span id="divErrortxtQuestion" style="display:none" class="RegisterErrormsg">不能少于4个字符大于30个字符</span>
</td>
</tr>
<tr>
<td style="width: 135px" class="Registerlefttd">
<span style="color:Red">*</span>找回密码答案:
</td>
<td style="width: 420px" class="Registertd">
<asp:TextBox ID="txtAnswer" runat="server" onBlur="checkText(this);" Width="400"></asp:TextBox>
</td>
<td class="Registertd">
<span id="divRighttxtAnswer" style="display:none" class="RegisterRightmsg">成功</span>
<span id="divBlanktxtAnswer" style="display:none" class="RegisterErrormsg">请输入密码问题答案!</span>
<span id="divErrortxtAnswer" style="display:none" class="RegisterErrormsg">不能少于4个字符大于30个字符</span>
</td>
</tr>
<tr>
<td style="width: 135px" class="Registerlefttd">
<span style="color:Red">*</span>E-mail:
</td>
<td style="width: 420px" class="Registertd">
<asp:TextBox ID="txtEmail" runat="server" onBlur="checkText(this);" Width="400"></asp:TextBox>
</td>
<td class="Registertd">
<span id="divInfotxtEmail" style="display:block" class="Registermsg">格式:exp@hezhongelectric.com</span>
<span id="divBlanktxtEmail" style="display:none" class="RegisterErrormsg">请输入邮箱地址!</span>
<span id="divRighttxtEmail" style="display:none" class="RegisterRightmsg">成功</span>
<span id="divErrortxtEmail" style="display:none" class="RegisterErrormsg">请输入正确的邮箱,例如:exp@hezhongelectric.com</span>
</td>
</tr>
<tr>
<td style="width: 135px" class="Registerlefttd">
<span style="color: #ff0000">*</span>公司名称:
</td>
<td style="width: 420px" class="Registertd">
<asp:TextBox ID="txtCompany" runat="server" onBlur="checkText(this);" Width="400"></asp:TextBox>
</td>
<td class="Registertd">
<span id="divBlanktxtCompany" style="display:none" class="RegisterErrormsg">请输入公司名称!</span>
<span id="divRighttxtCompany" style="display:none" class="RegisterRightmsg">成功</span>
<span id="divErrortxtCompany" style="display:none" class="RegisterErrormsg">不能大于200个字符</span>
</td>
</tr>
<tr>
<td style="width: 135px" class="Registerlefttd">
<span style="color: #ff0000">*</span>公司法人:
</td>
<td style="width: 420px" class="Registertd">
<asp:TextBox ID="txtRealName" runat="server" onBlur="checkText(this);"></asp:TextBox>
</td>
<td class="Registertd">
<span id="divBlanktxtRealName" style="display:none" class="RegisterErrormsg">请输入公司法人!</span>
<span id="divRighttxtRealName" style="display:none" class="RegisterRightmsg">成功</span>
<span id="divErrortxtRealName" style="display:none" class="RegisterErrormsg">不能大于50个字符</span>
</td>
</tr>
<tr>
<td style="width: 135px" class="Registerlefttd">
<span style="color: #ff0000">*</span>联系电话:
</td>
<td style="width: 420px" class="Registertd">
<asp:TextBox ID="txtTel" runat="server" onBlur="checkText(this);"></asp:TextBox>
</td>
<td class="Registertd">
<span id="divInfotxtTel" style="display:block" class="Registermsg">格式:86-0571-88888888 或 0571-88888888</span>
<span id="divBlanktxtTel" style="display:none" class="RegisterErrormsg">请输入联系电话!</span>
<span id="divRighttxtTel" style="display:none" class="RegisterRightmsg">成功</span>
<span id="divErrortxtTel" style="display:none" class="RegisterErrormsg">请输入正确的电话!</span>
</td>
</tr>
</table>
<table width="100%">
<tr>
<td style="width: 128px"></td>
<td style="width:420px;"><span style="color:#990000; font-weight:600;">选择填写其他信息</span>
<input id="Checkbox1" type="checkbox" onclick="Check();"/>显示高级选项
</td>
<td style="color:#333">带“<span style="color:Red">*</span>”为必填项目</td>
</tr>
</table>
<br />
<div>
<table id="othertable" width="100%" style="text-align:left; display:none;" cellpadding="0" cellspacing="0">
<tr>
<td style="width: 135px" class="Registerlefttd">
公司地址:
</td>
<td style="width: 420px" class="Registertd">
<asp:TextBox ID="txtAddress" runat="server" onBlur="checkText(this);" Width="400"></asp:TextBox>
</td>
<td class="Registertd">
<span id="divRighttxtAddress" style="display:none" class="RegisterRightmsg">成功</span>
<span id="divErrortxtAddress" style="display:none" class="RegisterErrormsg">不能大于300个字符</span>
</td>
</tr>
<tr>
<td style="width: 135px" class="Registerlefttd">
传真:
</td>
<td style="width: 420px" class="Registertd">
<asp:TextBox ID="txtFax" runat="server" onBlur="checkText(this);"></asp:TextBox>
</td>
<td class="Registertd">
<span id="divInfotxtFax" style="display:block" class="Registermsg">格式:86-0571-88888888 或 0571-88888888</span>
<span id="divRighttxtFax" style="display:none" class="RegisterRightmsg">成功</span>
<span id="divErrortxtFax" style="display:none" class="RegisterErrormsg">请输入正确的传真!</span>
</td>
</tr>
<tr>
<td style="width: 135px" class="Registerlefttd">
通讯地址:
</td>
<td style="width: 420px" class="Registertd">
<asp:TextBox ID="txtPostAddress" runat="server" onBlur="checkText(this);" Width="400"></asp:TextBox>
</td>
<td class="Registertd">
<span id="divRighttxtPostAddress" style="display:none" class="RegisterRightmsg">成功</span>
<span id="divErrortxtPostAddress" style="display:none" class="RegisterErrormsg">不能大于300个字符</span>
</td>
</tr>
<tr>
<td style="width: 135px" class="Registerlefttd">
公司主页:
</td>
<td style="width: 420px" class="Registertd">
<asp:TextBox ID="txtWebSite" runat="server" onBlur="checkText(this);" Width="400"></asp:TextBox>
</td>
<td class="Registertd">
<span id="divRighttxtWebSite" style="display:none" class="RegisterRightmsg">成功</span>
<span id="divErrortxtWebSite" style="display:none" class="RegisterErrormsg">不能大于100个字符</span>
</td>
</tr>
<tr>
<td style="width: 135px" class="Registerlefttd"> </td>
<td colspan="2" class="Registertd">
<table>
<tr><td>国 家:</td><td><asp:TextBox ID="txtCountry" runat="server"></asp:TextBox></td><td></td><td>地 区:</td><td><asp:TextBox ID="txtArea" runat="server"></asp:TextBox></td></tr>
</table>
</td>
</tr>
<tr>
<td style="width: 135px" class="Registerlefttd">
公司类型:
</td>
<td style="width: 420px" class="Registertd">
<asp:DropDownList ID="ddlClientType" runat="server">
<asp:ListItem Value="Agent">代理商</asp:ListItem>
<asp:ListItem Value="Distributor">分销商</asp:ListItem>
<asp:ListItem Value="Manufacturer">制造商</asp:ListItem>
<asp:ListItem Value="Service">服务商</asp:ListItem>
<asp:ListItem Value="Importer">进口商</asp:ListItem>
<asp:ListItem Value="Exporter">出口商</asp:ListItem>
<asp:ListItem Value="Other">其它</asp:ListItem>
</asp:DropDownList></td>
<td class="Registertd">
</td>
</tr>
</table>
</div>
<table width="100%" style="text-align:left;">
<tr>
<td colspan="3" align="center">
<asp:CheckBox ID="cbConfirm" runat="server" Text="同意条款

</td>
</tr>
</table>
</div>
</asp:Content>