您的位置:首页 > 编程语言

登录注册功能的实现,核心的验证代码

2017-10-06 09:27 821 查看
<script type="text/javascript">
//初始化模块
var singupApp = angular.module("singupApp", []);
//控制器事件
singupApp.controller("singCtrl", ["$scope", "$http", function($scope, $http) {
//初始化短信内容
$scope.smsMsg = "发送验证码";
//设置action为true
var active = true;
//设置时间为60秒
var second = 60;
//设计一个倒计时的方法
var secondInterval;

$scope.getcheckCode = function(telephone) {
//当发生点击事件后
if(active = false) {
return; //跳出当前方法不做任何操作
}

var telephones = /^1(3|5|7|8)\d{9}$/;
if(telephones.test(telephone)) {
//如果满足则发送短信
$http({
method: 'GET',
url: 'customer_sendSms.action',
params: {
telephone: telephone
}
}).error(function(data, status, headers, config) {
// 当响应以错误状态返回时调用
alert("短信发送出错请联系管理员");
});
} else {
//如果不满足
alert("手机的格式不正确");
return;
}

//发生点击事件后
active = false; //设置为false
//触发一个倒计时的方法  定时器
secondInterval = setInterval(function() {
//首先判断定时器的时间
if(second < 0) {
//设置为
$scope.smsMsg = "发送验证码";
$scope.$digest(); //强制刷新
active = true;
second = 60;
//关闭定时器
clearInterval(secondInterval);
secondInterval = "undefined";
} else {
//没有定时完成
$scope.smsMsg = second + "秒后重新发送";
$scope.$digest(); //强制刷新
second--;
//设置active为true
}
}, 1000);
}
}]);

$(function() {

//验证手机号
$("#inputtelephone").blur(function() {
//去数据库验证电话号码是否已经被注册
var telephone = $("#inputtelephone").val();
var telephones = /^1(3|5|7|8)\d{9}$/;
//利用post请求去数据库请求
$.post("telephone.action", {
"telephone": telephone
}, function(data) {
if(telephones.test(telephone)) {
alert(data);
} else {
alert("号码不符合规范,请重新输入");
}

}, "json");
});
//验证密码
$("#inputpassword").blur(function() {
//验证密码是否满足
var inputpassword = $("#inputpassword").val();
if(inputpassword.length < 6) {
alert("密码不足6位");
}
});

$("#affirminputpassword").blur(function() {
//验证密码是否满足
var inputpassword = $("#inputpassword").val();
var affirminputpassword = $("#affirminputpassword").val();
if(inputpassword != affirminputpassword) {
alert("前后密码不一致");
} else {
alert("正确匹配");
}
});

//验证邮箱
$("#inputemail").blur(function() {
var emails = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/;
var email = $("#inputemail").val();
if(emails.test(email)) {
alert("邮箱格式正确");
} else {
alert("邮箱格式不正确请重新输入");
}
});

//注册按钮之前验证 //判断是否被勾选
$("#registid").click(function() {
if($("#checkboxid").is(':checked')) {
//判断同意按钮是否被选中
alert("已经选中");
//判断选中按钮是否被选中 已经选中则提交表单
$("#customerForm").submit();
//$("#registid").href="javascript:$('#customerForm').submit()";
} else {
//没有选中则不提交
alert("请勾选速运快递服务协议");
//$("#registid").href="#";
}
});

});
</script>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: