日期:2014-05-16 浏览次数:20316 次
function checkName(){
var username = $('#username'),
val = $.trim(username.val()),
reg = /^[a-zA-Z][a-zA-Z0-9]{5,15}$/,
span = $('#username').next();
if(!reg.test(val)){//格式不正确
span.text(u_msg.empty);
}
$.ajax({
type: "post",
url: "inc/checkreg.php",
data: "username="+val,
beforeSend: function(){
span.text(u_msg.check);
},
success: function(data){
if(data == 0){ //用户名已存在
span.text(u_msg.ishas);
}
if(data == 1){//用户名可注册
span.text(u_msg.isok);
}
}
});
}
if(!reg.test(val)){//格式不正确
span.text(u_msg.empty);
return false;
}
<form action="form_action.asp" method="get" onsubmit='return checkName();'>