它山之石可以攻玉

键盘上的生活
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

PHP+AJAX会员注册

Posted on 2011-04-09 13:14  陈达辉  阅读(1139)  评论(0编辑  收藏  举报

reg.php:
<script language="javascript" src="ajaxlist.js"></script>
<script>
function check(){
checkUserName_1('username',16,'unamespan')
checkpw_1('password',6,'upw')
checkSame_1('password','passAgain','urpw')
checkrealname_1('realname',8,'urealname')
checktel_1('tel',14,'utel')
checkfax_1('fax',14,'ufax')
checkmobile_1('mobile',11,'umobile')
checkEmail_1('email','uemail')
var myform=document.myform;
if (myform.username.keytype==1){
return false;
}
if (myform.password.keytype==1){
return false;
}
if (myform.realname.keytype==1){
return false;
}
if (myform.tel.keytype==1){
return false;
}
if (myform.fax.keytype==1){
return false;
}
if (myform.email.keytype==1){
return false;
}
if (myform.mobile.keytype==1){
return false;
}
}
</script>


  <form name="myform" method="post" action="Reganswer.html" onSubmit="return check()">
  <input type="hidden" name="oktext" value="iiiooo" />
  <TABLE border=0 cellSpacing=1 cellPadding=3 width="100%" align="center">
              <tbody>
     <tr>
                <td height="25" align=right>会员帐号:</td>
                <td width="242" valign=top nowrap><INPUT onBlur="checkUserName_1('username',16,'unamespan')" size="30" onFocus="onFouces('unamespan')" name=username keytype2="uname" class="input_txt" keytype="1" style="height:22px; width:222px"> <strong><font color="#FF0000">*</font></strong></td>
                <td width="382" valign=top nowrap><SPAN class=gray id=unamespan>3-16个字符(a-z,0-9,_)</SPAN></td>
     </tr>
              <tr>
                <td height="25" align=right>会员密码:</td>
                <td><INPUT onBlur="checkpw_1('password',6,'upw')" onFocus="onFouces('upw')" class="input_txt" type=password maxLength=30 name=password keytype2="pw" keytype=1 style="height:22px; width:222px">
                  <strong><font color="#FF0000">*</font></strong></td>
                <td><SPAN class=gray id=upw>6-16个字符(a-z,a-z,0-9,_)</SPAN></td>
              </tr>
              <tr>
                <td height="25" align=right valign=middle>验证密码:</td>
                <td><INPUT onBlur="checkSame_1('password','passAgain','urpw')" onFocus="onFouces('urpw')" class="input_txt" type=password maxLength=30 name=passAgain keytype2="rpw" keytype="1" style="height:22px; width:222px">
                  <strong><font color="#FF0000">*</font></strong>
                <td><SPAN class=gray id=urpw>请再输入一次登陆密码。</SPAN></tr>

              <tr>
                <td height="25" colspan="3" align=center valign=middle><hr width="90%" color=#cccccc size=1></td>
              </tr>
                <tr valign=top>
                  <td height="25" align=right valign=middle>您的姓名:<strong><font color="#FF0000"></font></strong></td>
                  <td width="242" valign=top><INPUT onBlur="checkrealname_1('realname',8,'urealname')" class="input_txt" onFocus="onFouces('urealname')" type=text maxLength=30 name=realname keytype2="realn" keytype=1 size="30">
                  <strong><font color="#FF0000">*</font></strong></td>
                  <td width="382" valign=top><SPAN class=gray id=urealname>请输入您的姓名。</SPAN></td>
                </tr>
                <tr valign=top>
                  <td height="25" align=right valign=middle>您的性别:</td>
                  <td valign=top><input type=radio checked value=0 name=sex class="input_txt">
                    先生 &nbsp;
                    <input type=radio value=1 name=sex>
                    女士 </td>
                  <td valign=top>&nbsp;</td>
                </tr>
    <TR vAlign=top>
            <TD align="right" vAlign=middle>所在省份:</TD>
            <TD colspan="2"><SELECT name=area class="input_txt" onChange="ChangeSelect(document.myform.area.options[document.myform.area.selectedIndex].value);">
              <OPTION value="" selected>请选择省</OPTION>
       <option value='1'>浙江省</option><option value='3'>安徽省</option><option value='4'>北京</option><option value='5'>福建省</option><option value='6'>甘肃省</option><option value='7'>广东省</option><option value='8'>广西</option><option value='9'>贵州省</option><option value='10'>海南省</option><option value='11'>河北省</option><option value='12'>河南省</option><option value='13'>黑龙江</option><option value='14'>湖北省</option><option value='15'>湖南省</option><option value='16'>吉林省</option><option value='17'>江苏省</option><option value='18'>江西省</option><option value='19'>辽宁省</option><option value='20'>内蒙古</option><option value='21'>宁夏</option><option value='22'>青海</option><option value='23'>山东省</option><option value='24'>山西省</option><option value='25'>陕西省</option><option value='26'>上海</option><option value='27'>四川省</option><option value='28'>天津</option><option value='29'>西藏</option><option value='30'>新疆</option><option value='31'>云南省</option><option value='32'>重庆</option><option value='2161'>台湾</option><option value='2162'>香港</option><option value='2163'>澳门</option>
            </SELECT>
   <select name="city" class="input_txt">
   <option value="" selected="selected">请选择市</option>
   </select> <strong><font color="#FF0000">*</font></strong></TD>
            </TR>
    <TR vAlign=top>
   <TD align="right" valign="middle">工作单位:</TD>
   <TD><INPUT maxLength=80 class="input_txt" size=30 name=company></TD>
      <TD>&nbsp;</TD>
    </TR>
          <TR vAlign=top>
            <TD align="right" vAlign=middle>联系地址:</TD>
            <TD><font color=#ff6600 size=2><input class="input_txt" size=30 name=address></font></TD>
            <TD>&nbsp;</TD>
          </TR>
          <TR vAlign=top>
            <TD vAlign=middle align=right>邮  编:</TD>
            <TD><FONT color=#ff6600 size=2><INPUT class="input_txt" size=30 name=zip></FONT></TD>
            <TD>&nbsp;</TD>
          </TR>
                <tr valign=top>
                  <td height="25" align="right" valign=middle>电  话:<strong><font color="#FF0000"></font></strong></td>
                  <td><INPUT onBlur="checktel_1('tel',14,'utel')" class="input_txt" onFocus="onFouces('utel')" type=text maxLength=30 name=tel keytype2="uteln" keytype=1 size="30"> <strong><font color="#FF0000">*</font></strong></td>
                  <td><SPAN class=gray id=utel>请勿超过14个字符,格式例如:0571-88861928。</SPAN></td>
                </tr>
                <tr valign=top>
                  <td height="25" align=right valign=middle>传  真:</td>
                  <td><INPUT onBlur="checkfax_1('fax',14,'ufax')" class="input_txt" onFocus="onFouces('ufax')" type=text maxLength=30 name=fax keytype2="ufaxn" keytype=1 size="30"> <strong><font color="#FF0000">*</font></strong></td>
                  <td><SPAN class=gray id=ufax>请勿超过14个字符,格式例如:0571-88861928。</SPAN></td>
                </tr>
                <tr valign=top>
                  <td height="25" align=right valign=middle>邮  箱:<strong><font color="#FF0000"></font></strong></td>
                  <td><INPUT onBlur="checkEmail_1('email','uemail')" size="30" class="input_txt" onFocus="onFouces('uemail')" maxLength=64 name=email keytype2="eml" keytype="1"> <strong><font color="#FF0000">*</font></strong></td>
                  <td><SPAN class=gray id=uemail>请准确填写邮件地址,方便注册激活。</SPAN></td>
                </tr>
                <tr valign=top>
                  <td height="25" align="right" valign=middle>手  机:</td>
                  <td><INPUT onBlur="checkmobile_1('mobile',14,'umobile')" class="input_txt" onFocus="onFouces('umobile')" type=text maxLength=30 name=mobile keytype2="umobilen" keytype=1 size="30"> <strong><font color="#FF0000">*</font></strong></td>
                  <td><SPAN class=gray id=umobile>格式例如:13588888888。</SPAN></td>
                </tr>
                <tr>
                  <td height="25" align="right">咨询QQ:</td>
                  <td><input size=30 name=QQ maxlength="20" class="input_txt"></td>
                  <td>&nbsp;</td>
                </tr>

    </table></td>
                </tr>
                <tr>
                  <td height="45" colspan="3" align="right"></td>
                </tr>
              </tbody>
          </table></form>

ajaxlist.js

 

var username_help='3-16个字符(a-z,0-9,_)';
var username_ok='<img src=images/note_ok.gif valign=middle>';
var username_error='<img src=images/note_error.gif align=absbottom> 用户名超过了16个字符!';
var username_error_1='<img src=images/note_error.gif align=absbottom> 您的用户名输入格式不正确!';
var username_exist='<img src=images/note_error.gif align=absbottom> 您填写的用户名已经存在!';
var username_null='<img src=images/note_error.gif align=absbottom> 用户名不能为空!';
var password_help='6-16个字符(a-z,a-z,0-9,_)';
var password_too_simple='<img src=images/note_error.gif align=absbottom> 您设置的密码过于简单!';
var password_too_length='<img src=images/note_error.gif align=absbottom> 您设置的密码长度超过了16个字符!';
var password_ok='<img src=images/note_ok.gif valign=middle>';
var password_null='<img src=images/note_error.gif align=absbottom> 密码不能为空!';
var repassword_help='请再输入一次登陆密码!';
var repassword_unsame='<img src=images/note_error.gif align=absbottom> 输入的登陆密码不一致,请重新输入!';
var repassword_null='<img src=images/note_error.gif align=absbottom> 验证密码不能为空!';
var urealname_help='请输入您的姓名。';
var urealname_ok='<img src=images/note_ok.gif valign=middle>';
var urealname_null='<img src=images/note_error.gif align=absbottom> 姓名不能为空!';
var urealname_error='<img src=images/note_error.gif align=absbottom> 姓名超过了8个字符!';
var urealname_error2='<img src=images/note_error.gif align=absbottom> 姓名格式不正确!';
var utel_help='请勿超过14个字符,格式例如:0571-88861928。';
var utel_null='<img src=images/note_error.gif align=absbottom> 电话不能为空!';
var utel_error='<img src=images/note_error.gif align=absbottom> 电话超过了14个字符!';
var utel_error2='<img src=images/note_error.gif align=absbottom> 电话格式不正确!';
var ufax_help='请勿超过14个字符,格式例如:0571-88861928。';
var ufax_null='<img src=images/note_error.gif align=absbottom> 传真不能为空!';
var ufax_error='<img src=images/note_error.gif align=absbottom> 传真超过了14个字符!';
var ufax_error2='<img src=images/note_error.gif align=absbottom> 传真格式不正确!';
var umobile_help='格式例如:13588888888。';
var umobile_null='<img src=images/note_error.gif align=absbottom> 手机号码不能为空!';
var umobile_error='<img src=images/note_error.gif align=absbottom> 手机号码超过了11个字符!';
var umobile_error2='<img src=images/note_error.gif align=absbottom> 手机号码格式不正确!';
var email_help='请准确填写邮件地址,方便注册激活。';
var email_error='<img src=images/note_error.gif align=absbottom> 您的邮箱填写不正确!';
var email_exist='<img src=images/note_error.gif align=absbottom> 此邮箱已被注册,请输入其他邮箱地址!';
var email_null='<img src=images/note_error.gif align=absbottom> 邮箱不能为空!';
var email_ok='<img src=images/note_ok.gif valign=middle>';
var word_help='word_help';
var word_error='word_error';
var oTR;
var oTD;
//该函数可以创建我们需要的XMLHttpRequest对象
function getHTTPObject(){
var xmlhttp = false;
if(window.XMLHttpRequest){
xmlhttp = new XMLHttpRequest();
if(xmlhttp.overrideMimeType){
xmlhttp.overrideMimeType('text/xml');
}
}else{
try{
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
}catch(e){
try{
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}catch(E){ xmlhttp = false; }
}
}
return xmlhttp;
}
var http = getHTTPObject();

function getAbsLeft(e){
var l=e.offsetLeft;
while(e=e.offsetParent) l += e.offsetLeft;
return l;
}
function getAbsTop(e) {
var t=e.offsetTop;
while(e=e.offsetParent) t += e.offsetTop;
t=t+18;
return t;
}
//-------------------------------------------------------
function onFouces(str){
document.getElementById(str).className='word_help';
if(str=='unamespan'){
document.getElementById(str).innerHTML=username_help;
}else if(str=='upw'){
document.getElementById(str).innerHTML=password_help;
}else if(str=='uhrtype'){
document.getElementById(str).innerHTML=hrtype_help;
}else if(str=='urpw'){
document.getElementById(str).innerHTML=repassword_help;
}else if(str=='urealname'){
document.getElementById(str).innerHTML=urealname_help;
}else if(str=='utel'){
document.getElementById(str).innerHTML=utel_help;
}else if(str=='ufax'){
document.getElementById(str).innerHTML=ufax_help;
}else if(str=='umobile'){
document.getElementById(str).innerHTML=umobile_help;
}else if(str=='uemail'){
document.getElementById(str).innerHTML=email_help;
}
}
function backState(str){
if(str=='uname'){
document.getElementById('username').keytype=0;
document.getElementById('unamespan').className='gray';
document.getElementById('unamespan').innerHTML=username_ok;
}else if(str=='pw'){
document.getElementById('password').keytype=0;
document.getElementById('upw').className='gray';
document.getElementById('upw').innerHTML=password_ok;
}else if(str=="hr"){
document.getElementById('hrlibtype').keytype=0;
document.getElementById('uhrtype').className='gray';
document.getElementById('uhrtype').innerHTML=hrtype_help;

}else if(str=="rpw"){
document.getElementById('passAgain').keytype=0;
document.getElementById('urpw').className='gray';
document.getElementById('urpw').innerHTML=password_ok;

}else if(str=="realn"){
document.getElementById('realname').keytype=0;
document.getElementById('urealname').className='gray';
document.getElementById('urealname').innerHTML=urealname_ok;

}else if(str=="uteln"){
document.getElementById('tel').keytype=0;
document.getElementById('utel').className='gray';
document.getElementById('utel').innerHTML=urealname_ok;

}else if(str=="ufaxn"){
document.getElementById('fax').keytype=0;
document.getElementById('ufax').className='gray';
document.getElementById('ufax').innerHTML=urealname_ok;

}
else if(str=="umobilen"){
document.getElementById('mobile').keytype=0;
document.getElementById('umobile').className='gray';
document.getElementById('umobile').innerHTML=urealname_ok;

}
else if(str=="eml"){
document.getElementById('email').keytype=0;
document.getElementById('uemail').className='gray';
document.getElementById('uemail').innerHTML=email_ok;

}
}

function checkUserName_1(obj_str,num,obj_str1){
var obj=document.getElementById(obj_str);
var obj_help=document.getElementById(obj_str1);
obj.keytype=0;
if(obj.value.length==0){
obj.keytype=1;
obj_help.innerHTML=username_null;
obj_help.className=word_error;
return false;
}
if(obj.value.length>num){
obj.keytype=1;
obj_help.innerHTML=username_error;
obj_help.className=word_error;
return false;
}
//检查是否有不符合规定的字符
var name_str=obj.value;
//name_str=name_str.replace(/[\u4e00-\u9fa5]/g,'');
name_str=name_str.replace(/[a-zA-Z0-9_]/g,'');
name_str=name_str.replace(/-/g,'');
if(name_str!=''){
obj.keytype=1;
obj_help.innerHTML=username_error_1;
obj_help.className=word_error;
return false;
}
//检查用户名是否存在

var username =document.getElementById('username').value;

url="checkuserreg.php?username="+username; //如果用户名存在,chksn.asp的返回结果必须是“您填写的用户名已经存在”
//alert(url);
http.open("GET",url,true);
http.onreadystatechange = handleHttpResponseForUserName_1;
http.send(null);
if(obj.keytype==0){
backState("uname");
}
}
function handleHttpResponseForUserName_1(){
if(http.readyState == 4){
if (http.status == 200) {
returnStr=Trim(http.responseText); 
if(returnStr=="1"){
var obj_1=document.getElementById("unamespan");
obj_1.innerHTML=username_exist;
document.getElementById("username").keytype=1;
obj_1.className=word_error;
return false;
}
}
}
}
function checkpw_1(obj_str,num,obj_str1){
var obj=document.getElementById(obj_str);
var obj_help=document.getElementById(obj_str1);
obj.keytype=0;
if(obj.value.length==0){
obj.keytype=1;
obj_help.innerHTML=password_null;
obj_help.className=word_error;
return false;
}
if(obj.value.length<num){
obj.keytype=1;
obj_help.innerHTML=password_too_simple;
obj_help.className=word_error;
return false;
}
if(obj.value.length>16){
obj.keytype=1;
obj_help.innerHTML=password_too_length;
obj_help.className=word_error;
return false;
}
backState('pw');
}
function checkSame_1(obj_str,obj_str1,obj_targ){
var obj=document.getElementById(obj_str);
var obj1=document.getElementById(obj_str1);
var obj_help=document.getElementById(obj_targ);
obj.keytype=0;
if(obj1.value.length==0){
obj.keytype=1;
obj_help.innerHTML=repassword_null;
obj_help.className=word_error;
return false;
}
if(obj.value!=obj1.value){
obj.keytype=1;
obj_help.innerHTML=repassword_unsame;
obj_help.className=word_error;
return false;
}
backState('rpw');
}
function checkrealname_1(obj_str,num,obj_str1){
var obj=document.getElementById(obj_str);
var obj_help=document.getElementById(obj_str1);
obj.keytype=0;
if(obj.value.length==0){
obj.keytype=1;
obj_help.innerHTML=urealname_null;
obj_help.className=word_error;
return false;
}
if(obj.value.length>num){
obj.keytype=1;
obj_help.innerHTML=urealname_error;
obj_help.className=word_error;
return false;
}
var partten = /^[\u4e00-\u9fa5]{2,4}$/;
//var partten = /^(([0\+]\d{2,3}-)?(0\d{2,3})-)?(\d{7,8})(-(\d{3,}))?$/;
var num = obj.value;
if(partten.test(num))
{
backState('realn');
}
else
{
obj.keytype=1;
obj_help.innerHTML=urealname_error2;
obj_help.className=word_error;
}
}
function checktel_1(obj_str,num,obj_str1){
var obj=document.getElementById(obj_str);
var obj_help=document.getElementById(obj_str1);
obj.keytype=0;
if(obj.value.length==0){
obj.keytype=1;
obj_help.innerHTML=utel_null;
obj_help.className=word_error;
return false;
}
if(obj.value.length>num){
obj.keytype=1;
obj_help.innerHTML=utel_error;
obj_help.className=word_error;
return false;
}
var partten = /^((\d{2,3}-)?(\d{1,4})-)(\d{7,8})(-(\d{3,}))?$/;
//var partten = /^(([0\+]\d{2,3}-)?(0\d{2,3})-)?(\d{7,8})(-(\d{3,}))?$/;
var num = obj.value;
if(partten.test(num))
{
backState('uteln');
}
else
{
obj.keytype=1;
obj_help.innerHTML=utel_error2;
obj_help.className=word_error;
}
}
function checkfax_1(obj_str,num,obj_str1){
var obj=document.getElementById(obj_str);
var obj_help=document.getElementById(obj_str1);
obj.keytype=0;
if(obj.value.length==0){
obj.keytype=1;
obj_help.innerHTML=ufax_null;
obj_help.className=word_error;
return false;
}
if(obj.value.length>num){
obj.keytype=1;
obj_help.innerHTML=ufax_error;
obj_help.className=word_error;
return false;
}
var partten = /^((\d{2,3}-)?(\d{1,4})-)(\d{7,8})(-(\d{3,}))?$/;
//var partten = /^(([0\+]\d{2,3}-)?(0\d{2,3})-)?(\d{7,8})(-(\d{3,}))?$/;
var num = obj.value;
if(partten.test(num))
{
backState('ufaxn');
}
else
{
obj.keytype=1;
obj_help.innerHTML=ufax_error2;
obj_help.className=word_error;
}
}
function checkmobile_1(obj_str,num,obj_str1){
var obj=document.getElementById(obj_str);
var obj_help=document.getElementById(obj_str1);
obj.keytype=0;
if(obj.value.length==0){
obj.keytype=1;
obj_help.innerHTML=umobile_null;
obj_help.className=word_error;
return false;
}
if(obj.value.length>num){
obj.keytype=1;
obj_help.innerHTML=umobile_error;
obj_help.className=word_error;
return false;
}
var partten = /^(13[0-9]|15[0|3|6|7|8|9]|18[8|9])\d{8}$/;
//var partten = /^(([0\+]\d{2,3}-)?(0\d{2,3})-)?(\d{7,8})(-(\d{3,}))?$/;
var numm = obj.value;
if(partten.test(numm))
{
backState('umobilen');
}
else
{
obj.keytype=1;
obj_help.innerHTML=umobile_error2;
obj_help.className=word_error;
}
}
function checkEmail_1(obj_str,obj_str1){
var obj=document.getElementById(obj_str);
var obj_help=document.getElementById(obj_str1);
obj.keytype=0;
//验证电子邮件
var str="";
var email =obj.value;
if(email.length==0){
obj.keytype=1;
obj_help.innerHTML=email_null;
obj_help.className=word_error;
return false;
}else if (email.length < 8)
{
obj.keytype=1;
obj_help.innerHTML=email_error;
obj_help.className=word_error;
return false;
}else{
if (email.indexOf(".") <=0 || email.indexOf("@") == -1)
{ obj.keytype=1;
obj_help.innerHTML=email_error;
obj_help.className=word_error;
return false;
}
}

url="checkEmail.asp?email="+email; //如果email存在,checkEmail.asp的返回结果必须是“您使用的邮箱已经注册过,请登陆或者输入其他邮箱地址”
//alert(url);
http.open("GET",url,true);
http.onreadystatechange = handleHttpResponseEmail;
http.send(null);
}

function handleHttpResponseEmail(){
if(http.readyState == 4){
if (http.status == 200) {
returnStr=Trim(http.responseText);
if(returnStr=="1"){
var obj_1=document.getElementById("uemail");
obj_1.innerHTML=email_exist;
document.getElementById("email").keytype=1;
obj_1.className=word_error;
return false;
}else if(document.getElementById("email").keytype==0){
backState('eml');
}
}
}
}
//-------------------------------------------------------
function checkpw(obj,num){
var rownum=obj.parentElement.parentElement.rowIndex;
obj.keytype=0;
if(obj.value.length<num){
obj.keytype=1;
oTD=document.getElementById("reg_table").rows[rownum+1].cells[0];
oTD.innerHTML="<span class='"+word_error+"'>"+password_too_simple+"</span>"
return false;
}
hidden_text(obj);
}
function checkSame(obj,obj_str1){
var rownum=obj.parentElement.parentElement.rowIndex;
obj.keytype=0;
if(obj.value!=document.getElementById(obj_str1).value){
obj.keytype=1;
oTD=document.getElementById("reg_table").rows[rownum+1].cells[0];
oTD.innerHTML="<span class='"+word_error+"'>"+repassword_unsame+"</span>"
return false;
}
hidden_text(obj);
}
function show_text(obj){
var rownum=obj.parentElement.parentElement.rowIndex;
if(obj.keytype==0){
oTR=document.getElementById("reg_table").insertRow(rownum+1);
oTD=oTR.insertCell(0);
oTD.colSpan=2;
}else{
oTD=document.getElementById("reg_table").rows[rownum+1].cells[0];
}
if(obj.keytype2=="uname"){
oTD.innerHTML="<span class='"+word_help+"'>"+username_help+"</span>"
}else if(obj.keytype2=="hrtype"){
oTD.innerHTML="<span class='"+word_help+"'>"+hrtype_help+"</span>"
}else if(obj.keytype2=="pw"){
oTD.innerHTML="<span class='"+word_help+"'>"+password_help+"</span>"
}else if(obj.keytype2=="rpw"){
oTD.innerHTML="<span class='"+word_help+"'>"+repassword_help+"</span>"
}else if(obj.keytype2=="eml"){
oTD.innerHTML="<span class='"+word_help+"'>"+email_help+"</span>"
}

}
function hidden_text(obj){
var rownum=obj.parentElement.parentElement.rowIndex;
//if(obj.keytype==0){
document.getElementById("reg_table").deleteRow(rownum+1);
//}
}
function hidden_error(){
document.getElementById("word_error").style.display='none';
}
function Trim(str) {
return RTrim(LTrim(str));
}
function LTrim(str) {
return str.replace(/^[ \t\n\r]+/g, "");
}

function RTrim(str) {
return str.replace(/[ \t\n\r]+$/g, "");
}
function validator()
{
if(document.PersonForm.username.keytype==1)
{
return false; }
if(document.PersonForm.password.keytype==1)
{
return false; }
if(document.PersonForm.passAgain.keytype==1)
{
return false; }
if(document.PersonForm.email.keytype==1)
{
return false;}
if(document.PersonForm.isaccept.checked==false)
{
alert("您是否接受协议?");
document.PersonForm.isaccept.focus();
return false;
}
return true;
}
function changeimg(){
 document.getElementById('codepic').src='/member/code.asp?'+Math.random();
}
function ShowHideDiv(obj1){
 var obj1 = document.getElementById(obj1);
 obj1.style.display = obj1.style.display=="none" ? "":"none" ;
}

checkuserreg.php

 

 

<?php
header('ontent-Type:text/html;charset=GB2312');//避免输出乱码
$dbhost     ="localhost";
$dbuser     ="root";
$dbpassword = "123456";
$dbname     = "rc_miaosha";
mysql_connect($dbhost,$dbuser,$dbpassword) or die("error!");
mysql_query("set names 'gbk'");
mysql_select_db('rc_miaosha');

$username=trim($_GET['username']);//获取注册名
$sql="select u_username from rc_user where u_username='".$username."'";//查询会员名
$result=mysql_query($sql);
$num=mysql_num_rows($result);
$rows=mysql_fetch_array($result);
if($num<>0){
          echo "1";
}
else{
          echo "0";
}
mysql_close();//关闭数据库连接
?>