首页 > 代码库 > 短信验证

短信验证

//var clock=setInterval(‘time()‘,1000);
var time=60;
var clock=null;
function sendSms(obj){
var mobile=$(‘#mobile‘).val();
if(!(/^1[3|4|5|8][0-9]\d{4,8}$/.test(mobile))){
alert(‘请输入正确的手机号‘);
return;
}

if($(obj).html()==‘获取验证码‘&&clock==null){
$.ajax({
type: "get", //用get方式传输   
url: ‘{{url(‘sendsms‘)}}‘, //目标地址.
dataType: "json", //数据格式:JSON
data: {mobile: mobile},
success: function (data) {
if (data.status== 1) {//成功的处理
$(‘#code‘).val(data.msg);
// alert(‘短信验证码已发到您的手机,请查‘);
}
else {
alert(‘短信验证码发送失败,请重新发送‘);
//alert(data.html);
}
}
})
clock=setInterval(function(){
time--;
$(obj).html(time+‘秒后重新获取‘);
if(time==0){
clearInterval(clock);
$(obj).html(‘获取验证码‘);
time=60;
clock=null;
}
},1000)
}
}

function submit(){
var msg_code = $(‘.write_tel‘).val();
var code = $(‘#code‘).val();
console.log(msg_code);
if(msg_code && msg_code == code){
$(‘#verificationform‘).submit();
return ;
}
alert(‘验证码不正确‘);
}

短信验证