<script type="text/javascript">
var loginName,checkUN,password,confirmPwd,email,subBtn,userName,checkTel,tel;
$(init);
function init()
{
loginName = $("#loginName");
loginName.bind("blur",checkUserName);
password = $("#password");
confirmPwd = $("#confirmPwd");
userName = $("#userName");
userName.bind("blur",checkRN);
password.bind("blur",checkPwd);
confirmPwd.bind("blur",checkConfPwd);
email = $("#email");
email.bind("blur",checkEmail);
subBtn = $("#subBtn");
subBtn.bind("click",subUser);
checkTel = $("#checkTel");
tel = $("#tel");
tel.bind("blur",chkTel);
}
function checkUserName()
{
loginName = $("#loginName").val();
if(jQuery.trim(loginName)=="")
{
$("#loginName").focus();
$("#checkUN").css("color","Red");
$("#checkUN").text("用户名不能为空");
return false;
}
else
{
$("#checkUN").text("验证中...");
$.post("checkUser.ashx?tm="+new Date().getDate()+"&loginName="+loginName,function (result){
if(result=="0")
{
$("#checkUN").css("color","Red");
$("#checkUN").text("该用户名已存在");
subBtn.attr("disabled","disabled");
return false;
}
else if(result=="1")
{
$("#checkUN").css("color","Green");
$("#checkUN").text("该用户名可用");
subBtn.removeAttr("disabled");
return true;
}
});
}
}
function checkPwd()
{
password = $("#password").val();
if(jQuery.trim(password)=="")
{
$("#pwd").css("color","Red");
$("#pwd").text("密码不能为空");
return false;
}
else if(jQuery.trim(password).length<6)
{
$("#pwd").css("color","Red");
$("#pwd").text("长度不能小于6位数");
return false;
}
else
{
$("#pwd").css("color","Green");
$("#pwd").text("密码合法");
return true;
}
}
function checkConfPwd()
{
password = $("#password").val();
confirmPwd = $("#confirmPwd").val();
if(jQuery.trim(confirmPwd)=="")
{
$("#confPwd").css("color","Red");
$("#confPwd").text("确认密码不能为空");
return false;
}
else if(jQuery.trim(password)!=confirmPwd)
{
$("#confPwd").css("color","Red");
$("#confPwd").text("两次密码不一致");
return false;
}
else
{
$("#confPwd").css("color","Green");
$("#confPwd").text("确认密码合法");
return true;
}
}
function checkRN()
{
if(jQuery.trim(userName.val())=="")
{
$("#checkRN").css("color","Red");
$("#checkRN").text("真实姓名不能为空");
return false;
}
else
{
$("#checkRN").css("color","Green");
$("#checkRN").text("真实姓名合法");
return true;
}
}
function checkEmail()
{
var emailRegExp = new RegExp("[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:/.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?");
email = $("#email").val();
if (!emailRegExp.test(email)||email.indexOf('.')==-1)
{
$("#emailInfo").css("color","Red");
$("#emailInfo").text("电子邮箱不合法");
return false;
}
else
{
$("#emailInfo").css("color","Green");
$("#emailInfo").text("电子邮箱合法");
return true;
}
}
function chkTel()
{
if(tel.val().length!=11)
{
checkTel.css("color","Red");
checkTel.text("联系电话必需为11位");
return false;
}
else if(tel.val().substring(0,1)!='1')
{
checkTel.css("color","Red");
checkTel.text("联系电话以'1'开头");
return false;
}
else if(isNaN(tel.val()))
{
checkTel.css("color","Red");
checkTel.text("必需是0-9数字");
return false;
}
else if(tel.val().substring(0,1)=='1'&&tel.val().length==11)
{
checkTel.css("color","Green");
checkTel.text("联系电话合法");
return true;
}
}
function subUser()
{
if(!checkPwd()|!checkConfPwd()|!checkEmail()|!checkRN()|!chkTel())
{
return false;
}
else
{
$("#form1").submit();
}
}
</script>
在checkUser.ashx中有:
public class checkUser : IHttpHandler
{
Maticsoft.BLL.Users userBLL = new Maticsoft.BLL.Users();
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
string loginName = context.Request.QueryString.GetValues("loginName")[0];
List<Maticsoft.Model.Users> userList = userBLL.GetModelList("login_name='"+loginName+"'");
if (userList != null && userList.Count() > 0)
{
context.Response.Write("0");
}
else
{
context.Response.Write("1");
}
}
public bool IsReusable
{
get
{
return false;
}
}
}