首页 > php教程 > PHP源码 > 正文

ajax验证用户名二

WBOY
发布: 2016-06-08 17:30:15
原创
1398 人浏览过
<script>ec(2);</script>

现在我们把check.js文件代码来看看吧.

function c(){
  var uid =document.getElementById('uid').value;
  var pwd =document.getElementById('password').value;
  var pwd2=document.getElementById('password2').value;
  var mo =document.getElementById('mo').value;
  var name=document.getElementById('name').value;  
  
  if( uid=='' || uid.length>12 || uid.length     document.getElementById('u_info').innerHTML='

昵称长度为3-12字符!
'; 
    return false;
  }else{
    document.getElementById('u_info').innerHTML='
用户名长度3-12位
';
  }
  
  
  if(pwd =='' || pwd!=pwd2 || pwd.length12){
    document.getElementById('p_info').innerHTML='
密码不能为空或二次输入的密码不一致!';
    return false;
  }else{
    document.getElementById('p_info').innerHTML='
';
    document.getElementById('p_info1').innerHTML='
';
  }
  
  if( mo.match(/^[0-9]{3,4}-[0-9]{7,8}$/) || mo.match(/^(((d{3}))|(d{3}-))?13d{9}$/) ){
    document.getElementById('m_info').innerHTML='
';
  }else{
    document.getElementById('m_info').innerHTML='
手机13875888888与座机(0731-888888)';
    return false;
  }
  
  if( name=='' || name.length>12 || name.length     document.getElementById('n_info').innerHTML='
请输入你的真实姓名!';
    return false;    
  }else{
    document.getElementById('n_info').innerHTML='
';
  }
  
 


}

var xmlHttp = false;

function ajaxcreate(){

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();
 }
if(!xmlHttp){alert('Create Xmlhttp Fail ');return false;}
}


function ajax(){
 ajaxcreate();
 var xmvalue=document.getElementById("uid").value;
 var url="ajax_check.php?txt="+encodeURI(xmvalue);
 if (xmvalue== null || xmvalue.length>20 || xmvalue == "") return false;
 xmlHttp.open("POST",url,true);
 xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
 xmlHttp.send(xmvalue); 
 xmlHttp.onreadystatechange=returnstate; 
}
function returnstate(){
 if(xmlHttp.readyState != 4 ){
  document.getElementById("u_info").innerHTML="

正在验证请稍后...
";
 }
 if(xmlHttp.readyState == 4 ){
  document.getElementById("u_info").innerHTML=xmlHttp.responseText;
 }
}
相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门推荐
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!