<script>
$('#phone').focus(function() {
$('#msg').html("请输入合法的手机号");
$('#msg').show();
})
$('#phone').blur(function() {
var phone = $('#phone').val();
var phonePattern = /^1(3|4|5|7|8)\d{9}$/;
if(!phone || !(phonePattern.test(phone))) {
$('#msg').html("您输入的手机号码有误");
$('#msg').show();
} else {
$('#msg').hide();
}
})
$('#password').focus(function() {
$('#msg').html("输入6-20个字母、数字、下划线");
$('#msg').show();
})
$('#password').blur(function() {
var password = $('#password').val();
var pPattern = /^(\w){6,20}$/;
if(!password || !(pPattern.test(password))) {
$('#msg').html("您输入的密码有误");
$('#msg').show();
} else {
$('#msg').hide();
}
})
$('#loginHandle').click(function() {
var phone = $('#phone').val();
var password = $('#password').val();
var phonePattern = /^1(3|4|5|7|8)\d{9}$/;
var pPattern = /^(\w){6,20}$/;
//校验手机号的合法性
if(phone == null || phone == '') {
$('#msg').html("手机号不能为空");
$('#msg').show();
$("#phone").focus();
return;
};
if(!(phonePattern.test(phone))) {
$('#msg').html("您填写的手机号码有误,请重新填写");
$('#msg').show();
return;
}
/*矫正密码合法性*/
if(password == null || password == '') {
$('#msg').html("密码不能为空");
$('#msg').show();
return;
}
if(!(pPattern.test(password))) {
$('#msg').html("只能输入6-20个字母、数字、下划线 ");
$('#msg').show();
return;
}
/*登录请求*/
$.ajax({
type: "post",
url: "http://47.111.188.27:8080/gsgkzyl/user/login",
xhrFields: {
withCredentials: true
},
crossDomain: true,
//contentType: "application/x-www-form-urlencoded; charset=UTF-8",
data: {
mobile: phone,
password: password,
},
success: function(log) {
console.log(log)
if(log.status == 0) {
SetCookie('userId',log.redisUserInfo.userId);
layer.alert('登录成功', function() {
window.location.href = "dynamic/news.html"
})
} else {
$('#msg').show();
$('#msg').html(log.msg);
}
}
});
})
</script>
登录、注册获取焦点、失去焦点验证
最新推荐文章于 2022-10-13 21:33:15 发布