var user = $("user");
var userCheck = $("userCheck");
var reg = /^[a-zA-Z][a-zA-Z0-9]{5,15}$/;
function checkUser(){
if(user.value == null || user.value.length == 0){
userCheck.innerHTML = "用户名不能为空";
} else if(user.value.length < 6){
userCheck.innerHTML = "用户名不能小于6位";
} else if(!reg.test(user.value)){
userCheck.innerHTML = "用户名必须以字母开头,字母数字结尾,最长不能超过16位";
} else{
checkHaveUser(user.value);
// userCheck.innerHTML = "用户名正确";
}
}
var xmlHttp; function getXmlHttp(){
if(window.ActiveXObject){
xmlHttp = new ActiveXObject("MICROSOFT.XMLHTTP");
}else if(window.XMLHttpRequest){
xmlHttp = new XMLHttpRequest();
}
}
function checkHaveUser(obj){
getXmlHttp();
xmlHttp.open("GET","checkUser.php?userName="+obj,true);
xmlHttp.onreadystatechange = function(){
if(xmlHttp.readyState == 4){
if(xmlHttp.status == 200){
var str = parseInt(xmlHttp.responseText);
if(str > 0){
userCheck.innerHTML = "用户已经存在,请选择其他用户名";
}else{
userCheck.innerHTML = "可以注册";
}
}
}
}
xmlHttp.send(null); }
function $(id){
return document.getElementById(id);
}