jsp.file
欢迎注册EasyMall/* 注册表单的js校验 */
var formObj = {
/* 检查输入项是否为空 */
"checkNull" : function(name, msg){
var value = $("input[name='"+name+"']").val().trim();
//清空之前的提示消息
formObj.setMsg(name, "");
if(value == ""){
formObj.setMsg(name, msg);
return false;
}
return true;
},
/* 设置错误提示消息 */
"setMsg" : function(name, msg){
$("#"+name+"_msg").html(msg);
$("#"+name+"_msg").css("color", "red");
}
,
/* 注册表单js校验 */
"checkForm" : function(){
//1.非空校验
var res1 = formObj.checkNull("username", "用户名不能为空");
var res2 = formObj.checkNull("password", "密码不能为空");
var res3 = formObj.checkNull("password2", "确认密码不能为空");
var res4 = formObj.checkNull("nickname", "昵称不能为空");
var res5 = formObj.checkNull("email", "邮箱不能为空");
var res6 = formObj.checkNull("valistr", "验证码不能为空");
//2.两次密码是否一致
var res7 = formObj.checkPassword("password", "两次密码不一致");
//3.邮箱格式是否正确
var res8 = formObj.checkEmail("email", "邮箱格式不正确");
return res1&&res2&&res3&&res4&&res5&&res6&&res7&&res8;
},
/* 检查邮箱格式是否正确 */
"checkEmail" : function(name, msg){
var email = $("input[name='"+name+"']").val().trim();
if(email == ""){
formObj.setMsg("email", "邮箱不能为空");
}
if(email != ""){
var reg = /^\w+@\w+(\.\w+)+$/;
if(!reg.test(email)){
formObj.setMsg(name, msg);
return false;
}
}
return true;
}
,
/* 检查两次密码是否一致 */
"checkPassword" : function(name, msg){
var psw1 = $("input[name='"+name+"']").val().trim();
var psw2 = $("input[name='"+name+"2']").val().trim();
if(psw2 == ""){
formObj.setMsg(name+"2", "确认密码不能为空");
}
if(psw1 != "" && psw2 != ""){
if(psw1 != psw2){
formObj.setMsg(name+"2", msg);
return false;
}
}
return true;
}
}
/* 利用ajax实现用户名是否存在的校验 */
function ajaxCheckeUsername(thisobj){
//非空校验
if(!formObj.checkNull("username", "用户名不能为空!")){
return;
}
//获取用户名
var username = thisobj.value;
//使用ajax检查用户名是否存在
$("#username_msg").load("${app}/servlet/AjaxCheckUsernameServlet", {"username" : username});
}
欢迎注册EasyMall
${ requestScope.msg } | |
用户名: | οnblur="ajaxCheckeUsername(this)" οnfοcus="formObj.setMsg('username', '')" value="${ param.username }"/> |
密码: | οnblur="formObj.checkNull('password', '密码不能为空')" οnfοcus="formObj.setMsg('password', '')" value="${ param.password }"/> |
确认密码: | οnblur="formObj.checkPassword('password', '两次密码不一致')" οnfοcus="formObj.setMsg('password2', '')" value="${ param.password2 }"/> |
昵称: | οnblur="formObj.checkNull('nickname', '昵称不能为空')" οnfοcus="formObj.setMsg('nickname', '')" value="${ param.nickname }"/> |
邮箱: | οnblur="formObj.checkEmail('email', '邮箱格式不正确')" οnfοcus="formObj.setMsg('email', '')" value="${ param.email }"/> |
验证码: | οnblur="formObj.checkNull('valistr', '验证码不能为空')" οnfοcus="formObj.setMsg('valistr', '')" value="${ param.valistr }"/> |
function changeImage(thisobj){
thisobj.src = "${app}/servlet/ValiImageServlet?time="+new Date().getTime();
}