/**
* Created by zhanglingling on 2017/1/6.
*/
var check_lg = (function(){
var check = function regi_check() {
$(".user_login :input").blur(function () {
var $parent = $(this).parent();
$parent.find(".formtips").remove();
var $name = $(this).attr("name");
console.log($name);
switch ($name) {
//用户名验证
case "userName":
if (this.value == "" || this.value.length < 6) {
var errorMsg = '请输入至少6位的用户名';
$parent.append('<span class="formtips onError"><i class="fa fa-close"></i>' + errorMsg + '</span>');
} else {
/* var okMsg = '填写正确';*/
$parent.append('<span class="formtips onSuccess"><i class="fa fa-check"></i></span>');
}
break;
//手机号码验证
case "login_tel" :
if (this.value == "" || !(/^\d{11}$/.test(this.value))) {
var errorMsg = '请输入11位数字的手机号码';
$parent.append('<span class="formtips onError"><i class="fa fa-close"></i>' + errorMsg + '</span>');
}
else {
$parent.append('<span class="formtips onSuccess"><i class="fa fa-check"></i></span>');
}
break;
//密码验证
case "login_pwd":
if (this.value == "" || this.value.length < 6) {
var errorMsg = '请输入至少6位的密码';
$parent.append('<span class="formtips onError"><i class="fa fa-close"></i>' + errorMsg + '</span>');
} else {
$parent.append('<span class="formtips onSuccess"><i class="fa fa-check"></i></span>');
}
break;
//再次密码验证
case "login_surePwd":
var $value = $("[name='login_pwd']").val();
if (this.value == "" || this.value.length < 6) {
var errorMsg = '请输入至少6位的密码';
$parent.append('<span class="formtips onError"><i class="fa fa-close"></i>' + errorMsg + '</span>');
} else if (this.value != $value) {
var errorMsg = '两次输入密码不一致';
$parent.append('<span class="formtips onError"><i class="fa fa-close"></i>' + errorMsg + '</span>');
}
else {
$parent.append('<span class="formtips onSuccess"><i class="fa fa-check"></i></span>');
}
break;
////邮箱验证
case "login_email":
if (this.value == "" || ( this.value != "" && !/.+@.+\.[a-zA-Z]{2,4}$/.test(this.value) )) {
var errorMsg = '请输入正确邮箱地址';
$parent.append('<span class="formtips onError"><i class="fa fa-close"></i>' + errorMsg + '</span>');
} else {
$parent.append('<span class="formtips onSuccess"><i class="fa fa-check"></i></span>');
}
break;
////验证码
case "yanzm":
if (this.value == "") {
$parent.append('<span class="formtips onError"><i class="fa fa-close"></i></span>');
} else {
$parent.append('<span class="formtips onSuccess"><i class="fa fa-check"></i></span>');
}
break;
}
});
};
return {
check_login:check
}
})();
check_lg.check_login();