ASP+ajax实用用户唯一性检查和注册

本文详细介绍了注册页面的用户信息填写、验证流程及注意事项,包括邮箱格式校验、密码复杂度要求、会员名唯一性检查等关键步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
代码如下:

reg.asp:

<!-- #include file="../inc/web_conn.asp" -->
<!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>Kenvi.cn</title>
<META name="keywords" content="kenvi" />
<META name="description" content="kenvi.cn" /> 
<link href="zp.css" rel="stylesheet" type="text/css" />
<script language="javascript" src="/inc/main.js"></script>
<style type="text/css">
body {
 margin-left: 0px;
 margin-top: 0px;
 margin-right: 0px;
 margin-bottom: 0px;
}
.dd { width:200px; text-align:center;}
.STYLE2 {
 font-size: 14px;
 font-weight: bold;
 color: #FFFFFF;
}
.z0056C2 {color:#0056C2;}
</style>
<script language="javascript">
<!--
var msg ;
var li_ok='images/li_ok.gif';
var li_err='images/li_err.gif'
var bname_m=false;
msg=new Array(
 "推荐使用:· 网易邮箱 ·QQ邮箱 ·SOHU邮箱",
 "请输入4-14位字符,英文、数字的组合。",
 "请输入6位以上字符,不允许空格。",
 "请重复输入上面的密码。",
 "请输入邮箱地址"
 )
 //document.getElementById("d_email").innerHTML=msg[0];
 //document.getElementById("d_pass").innerHTML=msg[2];
 //document.getElementById("d_pass2").innerHTML=msg[3];
 //document.getElementById("d_name").innerHTML=msg[1];
var xmlHttp = false;
try {
  xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
  try {
    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (e2) {
    xmlHttp = false;
  }
}
if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
  xmlHttp = new XMLHttpRequest();
}
 
function on_input(objname){
 var strtxt;
 var obj=document.getElementById(objname);
 obj.className="d_on";
 //alert(objname);
 switch (objname){
  case "d_email":
   strtxt=msg[4];
   break;
  case "d_name":
   strtxt=msg[1];
   break;
  case "d_pass":
   strtxt=msg[2];
   break;
  case "d_pass2":
   strtxt=msg[3];
   break;
 }
 obj.innerHTML=strtxt;
}
 
function out_email(){
 var obj=document.getElementById("d_email");
 var str=document.getElementById("ys_email").value;
 var chk=true;
 if (str==''|| !str.match(/^[/w/./-]+@([/w/-]+/.)+[a-z]{2,4}$/ig)){chk=false}
 if (chk){
  obj.className="d_ok";
  obj.innerHTML='电子邮箱地址已经输入。';
  document.getElementById("d_email_img").src=li_ok;
 }else{
  obj.className="d_err";
  obj.innerHTML=msg[4];
  document.getElementById("d_email_img").src=li_err;
 }
 return chk;
}
 
function out_upwd1(){
 var obj=document.getElementById("d_pass");
 var str=document.getElementById("ys_pass").value;
 var chk=true;
 if (str=='' || str.length<6 || str.length>14){chk=false;}
 if (chk){
  obj.className="d_ok";
  obj.innerHTML='密码已经输入。';
  document.getElementById("d_pass_img").src=li_ok;
 }else{
  obj.className="d_err";
  obj.innerHTML=msg[2];
  document.getElementById("d_pass_img").src=li_err;
 }
 return chk;
}
 
function out_upwd2(){
 var obj=document.getElementById("d_pass2");
 var str=document.getElementById("ys_pass2").value;
 var chk=true;
 if (str!=document.getElementById("ys_pass").value||str==''){chk=false;}
 if (chk){
  obj.className="d_ok";
  obj.innerHTML='重复密码输入正确。';
  document.getElementById("d_pass2_img").src=li_ok;
 }else{
  obj.className="d_err";
  obj.innerHTML=msg[3];
  document.getElementById("d_pass2_img").src=li_err;
 }
 return chk;
}
 
function chk_reg(){
 var chk=true
 if (document.getElementById("ys_name").value==''){chk=false;
     d_name.className="d_err";
  d_name.innerHTML=msg[1];
  document.getElementById("d_uname_img").src=li_err;
 }
 if (!out_upwd1()){chk=false}
 if (!out_upwd2()){chk=false}
 if (!out_email()){chk=false}
 if(chk){
 document.getElementById('save_stat').innerHTML='<img src="images/loading.gif" align="absmiddle" />数据提交中……请稍候……'
 document.getElementById('regbotton').disabled='disabled';
 var username=document.regform.ys_name.value;
 var password=document.regform.ys_pass.value;
 var repassword=document.regform.ys_pass2.value;
 var email=document.regform.ys_email.value;
 //var url2 = "reg.asp?action=save&ys_name=+ "escape(username)"+&password=+ "escape(username)"+&email="+escape(email);
 //var url2="reg.asp?action=save&username="+escape(username)+"&password="+escape(password)+"&email="+escape(email);
    xmlHttp.open("POST", "saveuser.asp", true);
 xmlHttp.setRequestHeader('Content-type','application/x-www-form-urlencoded');
    xmlHttp.onreadystatechange = saveuser;
    xmlHttp.send("username="+escape(username)+"&password="+escape(password)+"&email="+escape(email));  
 }
}
 
function saveuser() {
  if (xmlHttp.readyState < 4) {
    d_name.innerHTML="loading...";
  }
  if (4==xmlHttp.readyState){
            if (200==xmlHttp.status){
                var date=xmlHttp.responseText;
                if (date==1){
      alert("用户注册成功!");
      //window.location.href='//exhibit';
      window.location.href="reg.asp"; 
    }else{
       alert("注册发生错误!");
       window.location.href="reg.asp";
       }
            }else{
                alert("error");
            }
        }
 
 }
 
function callServer() {
  var u_name = document.getElementById("ys_name").value;
  if ((u_name == null) || (u_name == "")) {
        d_name.className="d_err";
  d_name.innerHTML=msg[1];
  document.getElementById("d_uname_img").src=li_err;
  chk=false
   return chk;};
    xmlHttp.open("POST", "checkuser.asp", true);
 xmlHttp.setRequestHeader('Content-type','application/x-www-form-urlencoded');
 xmlHttp.onreadystatechange = updatePage;
 xmlHttp.send("username="+escape(u_name));  
}
 
function updatePage() {
  if (xmlHttp.readyState < 4) {
    d_name.innerHTML="loading...";
  }
  if (xmlHttp.readyState == 4 && 200==xmlHttp.status) {
    var response = xmlHttp.responseText;
   if (response==1)
   {
    d_name.className="d_ok";
  d_name.innerHTML='恭喜用户名可以使用。';
  document.getElementById("d_uname_img").src=li_ok;
      }
      else{
   d_name.className="d_err";
   document.getElementById("d_uname_img").src=li_err;
   d_name.innerHTML="用户名已占用,请重新注册";
      }
  }
  }
-->
</script>
</head>
 
<body>
<!-- #include file="../top.asp" -->
<table width="857" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td height="20" align="left" valign="top">&nbsp;</td>
  </tr>
  <tr>
    <td width="260" height="20" align="left" valign="top"><img src="images/zc-top.jpg" width="857" height="20" /></td>
  </tr>
  <tr>
    <td height="20" align="left" valign="top"><table width="100%" cellspacing="0" cellpadding="0">
      <tr>
        <td width="3" bgcolor="FF7300"></td>
        <td align="center"><form id="regform" name="regform" method="post" action="reg.asp">
          <table width="90%" cellspacing="0" cellpadding="0">
          <tr>
            <td height="15" colspan="4"></td>
            </tr>
          <tr>
            <td height="35" colspan="4" align="left" class="blut_title">请填写注册信息:</td>
            </tr>
          <tr>
            <td width="12%" align="left"><img src="images/button.jpg" width="11" height="11" id="d_email_img"/>&nbsp;Email:</td>
            <td width="30%" height="30" align="left"><input name="ys_email" type="text" id="ys_email" size="30" onFocus="on_input('d_email')" onBlur="out_email()" /></td>
            <td width="42%" align="left" colspan="2" class="yellow12" id="d_email">推荐使用:· 网易邮箱 ·QQ邮箱 ·SOHU邮箱</td>
          </tr>
          <tr>
            <td align="left"><img src="images/button.jpg" width="11" height="11" id="d_uname_img"/>&nbsp;会 员 名:</td>
            <td height="30" align="left"><input name="ys_name" type="text" id="ys_name" size="30" onFocus="on_input('d_name')" onBlur="callServer()"/></td>
            <td align="left" class="z666_unlink" id="d_name" colspan="2">须以字母开头,至少4位</td>
          </tr>
          <tr>
            <td align="left"><img src="images/button.jpg" width="11" height="11" id="d_pass_img"/>&nbsp;密  码:</td>
            <td height="30" align="left"><input name="ys_pass" type="password" id="ys_pass" size="30" onFocus="on_input('d_pass')" onBlur="out_upwd1()"/></td>
            <td colspan="2" align="left" class="z666_unlink" id="d_pass">密码设置至少4位,请区分大小写</td>
            </tr>
          <tr>
            <td align="left"><img src="images/button.jpg" width="11" height="11" id="d_pass2_img"/>&nbsp;重复密码:</td>
            <td height="30" align="left"><input name="ys_pass2" type="password" id="ys_pass2" size="30" onFocus="on_input('d_pass2')" onBlur="out_upwd2()"/></td>
            <td colspan="2" align="left" class="z666_unlink" id="d_pass2"></td>
          </tr>
          <tr>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
          </tr>
          <tr>
            <td height="1" colspan="4" background="images/dian.jpg"></td>
            </tr>
          <tr>
            <td height="46" colspan="4" align="center">
              <label>
              <!--<input type="image" name="regbotton" src="images/reg.jpg" onclick="chk_reg();" />-->
     <input type="button" name="submit" value="OK!确认提交注册信息" onclick="chk_reg();" id="regbotton">
              </label><div id="save_stat"></div></td>
            </tr>
        </table>
        </form>
        </td>
        <td width="3" bgcolor="FF7300"></td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td height="20" align="left" valign="top"><img src="images/zc-bottom.jpg" width="857" height="11" /></td>
  </tr>
</table>
<!-- #include file="../bottom.asp" -->
</body>
</html>
===================
zp.css

/* CSS Document */
 
body {font-family:"宋体"; font-size:12px; color:#333333; line-height:20px;}
 
a:link {color: #333333;text-decoration: none;}
a:visited ,a:active {text-decoration: none;color: #333333;}
a:hover {text-decoration: underline;color: #003278;}
 
a.blue12:link {color: #001D4C;text-decoration: none;}
a.blue12:visited ,a.blue12:active {text-decoration: none;color: #001D4C;}
a.blue12:hover {text-decoration: underline;color: #FF6600;}
 
 
a.black14:link {color: #333333;text-decoration: none; font-size:14px; font-weight:bold; line-height:24px;}
a.black14:visited ,a.black14:active {text-decoration: none; font-size:14px; font-weight:bold;color: #333333; line-height:24px;}
a.black14:hover {text-decoration: underline;color: #FF6600;font-size:14px; font-weight:bold; line-height:24px;}
 
 
 
a.title_kh:link ,a.title_kh:visited {color: #333333;text-decoration: none;}
a.title_kh:hover { text-decoration: none;color:#FF6600; font-size:120%;}
a.title_kh:active {text-decoration: none; color:#FF6600;}
 
a.yellow:link ,a.yellow:visited {color: #FF6600;text-decoration: none;}
a.yellow:hover { text-decoration: underline;color:#003278; }
a.yellow:active {text-decoration: none; color:#FF6600;}
 
 
a.tj:link ,a.tj:visited {color: #FF0000;text-decoration: none;}
a.tj:hover { text-decoration: underline;color:#003278; }
a.tj:active {text-decoration: none; color:#003278;}
 
 
a.blue14:link ,a.blue14:visited {color: #001D4C;text-decoration: none; font-weight:bold; font-size:14px}
a.blue14:hover { text-decoration: none;color:#FF6600; font-weight:bold; font-size:14px }
a.blue14:active {text-decoration: none; color:#001D4C; font-weight:bold; font-size:14px}
 
.img {border:1px solid  #cccccc;}
.zt_table {border:1px solid  #DDDBDB;}
 
.zt_title { color:#FF6600; font-weight:bold; font-size:14px;}
.blut_title { color:#003278; font-weight:bold; font-size:14px;}
.blut12_unlink { color:#003399; font-weight:bold; }
 
.blue {color:#003278;}
.yellow12 {color:#FF3300;}
.yellow14{color:#FF3300; font-size:14px;}
 
.end_title {font-size:24px; font-family:"黑体"; color:#003278;}
.end_zw {font-size:14px; line-height:24px;}
.z666_unlink {color:#666666;}
 
 
.wywg_nolink {color: #FF6600;font-weight:bold; font-size:14px;}
a.wywg:link ,a.wywg:visited {color: #FF6600;text-decoration: underline; font-weight:bold; font-size:14px;}
a.wywg:hover { text-decoration: underline;color:#FF7F12; font-weight:bold; font-size:14px; }
a.wywg:active {text-decoration: underline; color:#FF6600; font-weight:bold; font-size:14px;}
 
a.zc:link ,a.zc:visited {color: #FF6600;text-decoration: underline; }
a.zc:hover { text-decoration: underline;color:#FF7F12; }
a.zc:active {text-decoration: underline; color:#FF6600; }
 
.d_default{
padding:2px 0 2px 4px;
border:1px solid #f7f7f7 ;
}
.d_on{
padding:2px 0 2px 4px;
border:1px solid #FFCC00;
color:#000;
background-color:#FFFFDD;
}
.d_ok{
padding:2px 0 2px 24px;
border:1px solid #00BE00;
color:#000;
background:#E6FFE6 url(li_ok.gif) no-repeat 4px;
}
.d_err{
border:1px solid #F30;
color:#F00;
padding:2px 0 2px 24px;
background:#FFF1E4 url(li_err.gif) no-repeat 4px;
}
========================
checkuser.asp:
===========================
<!-- #include file="../inc/conn.asp" -->
<%
    Response.ContentType = "text/html" 
  Response.Charset = "gb2312"
     ys_name=trim(request("username"))
    set rs=server.createobject("adodb.recordset")
 sql="select ys_name,id from ys_imember where ys_name='"&ys_name&"'"
 rs.open sql,conn,1,1
 if rs.bof and rs.eof then
 response.write "1"
 else
 response.write "0"
 end if
 rs.close
 set rs=nothing
%>
saveuser.asp:

<!-- #include file="../inc/conn.asp" -->
<%ys_name=request("username")
ys_pass=request("password")
ys_email=request("email")
set jrs=server.CreateObject("adodb.recordset")
jsql="select ys_name,id from ys_imember where ys_name='"&ys_name&"'"
jrs.open jsql,conn,1,1
if jrs.eof and jrs.bof then
 set rs=server.CreateObject("adodb.recordset")
 sql="select * from ys_imember where id is null"
 rs.open sql,conn,1,3
 rs.addnew
 rs("ys_name")=ys_name
 rs("ys_pass")=ys_pass
 rs("ys_email")=ys_email
 rs.update
 Session("ys_userame")=ys_name
 rs.close
 set rs=nothing
 response.write "1"
else
   response.write "0"
end if
jrs.close
set jrs=nothing
%>
http://www.corange.cn/archives/2008/03/456.html
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值