var userid = $("username");
var usersp = $("usersp");
var reg = /^[A-Za-z0-9_\-\u4e00-\u9fa5]+$/;
function $(id){
return document.getElementById(id);
} function userget(){
if(userid.value == null || userid.value.length ==0){
usersp.innerHTML = "用户名不能为空";
usersp.style.color = "red";
usersp.style.fontSize = "15px";
}else if (userid.value.length < 6){
usersp.innerHTML = "用户名不能小于6位";
usersp.style.color = "red";
usersp.style.fontSize = "15px";
}else if(!reg.test(userid.value)){
usersp.innerHTML =
"用户名必须以字母开头,由字母、数字和__组成,最长不超过16位";
usersp.style.color = "red";
usersp.style.fontSize = "15px";
}else{
checkHaveUser();
usersp.innerHTML = ""; } }
//ajax判断 var xmlHttp; function getXmlHttp(){
if(window.ActiveXObject){
xmlHttp = new ActiveXObject("MICROSOFT.XMLHTTP");
}else if(window.XMLHttpRequest){
xmlHttp = new XMLHttpRequest();
} } function checkHaveUser(){
getXmlHttp();
var f = false;
xmlHttp.open("get","../model/check3.php?username="+usersp.value,false);
xmlHttp.onreadystatechange = function(){
if(xmlHttp.readyState == 4){
if(xmlHttp.status == 200){
var str = xmlHttp.responseText;
if(str == "ok"){
usersp.innerHTML
= "用户名已存在,请选择其他用户名";
return false;
}else{
usersp.innerHTML
= "可以注册";
return true;
}
}
}
} xmlHttp.send(null);
return f;
}
//密码验证 var pwd = $("password");
var mm = $("pwdsp");
var reg1 = /^[A-Za-z0-9_-]+$/; function $(id){
return document.getElementById(id);
} function pwdget(){
if(pwd.value == null || pwd.value.length == 0){
mm.innerHTML = "密码不能为空";
mm.style.color = "red";
mm.style.fontSize = "15px";
}else if(pwd.value.length<6){
mm.innerHTML = "密码不能小于6位";
mm.style.color = "red";
mm.style.fontSize = "15px";
}else{
mm.innerHTML = "";
}
}
//邮箱验证 var e_mail = $("e_mail");
var mailsp = $("mailsp");
var reg2 =
/\w+((-w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+/;
function $(id){
return document.getElementById(id);
} function mailget(){
if(e_mail.value == null || e_mail.value.length == 0){
mailsp.innerHTML = "邮箱不能为空";
mailsp.style.color = "red";
mailsp.style.fontSize = "15px";
}else if(!reg2.test(e_mail.value)){
mailsp.innerHTML = "邮箱由字母数字组成";
mailsp.style.color = "red";
mailsp.style.fontSize = "15px"; }
}