手机发送短信JS验证

时间:2023-12-14 21:32:26
     function tj() {
var phone = jQuery('#phone').val();
var code = jQuery('#verificationcode').val();
var password = jQuery('#password').val();
var rpassword = jQuery('#rpassword').val();
var type = "开户";
if (phone.length == 0 || phone == '请输入您的手机号码') {
alert("您的手机号码不能为空!");
jQuery('#phone').focus();
return false;
}
if (phone.length > 0) {
var ab = /^(13[0-9]|15[0-9]|18[0-9])\d{8}$/;
if (ab.test(phone) == false) {
alert("您的手机号码不正确!");
jQuery('#phone').focus();
return false;
}
}
if (code.length == 0 || code == '请输入手机验证码') {
alert("您的手机验证码不能为空!");
jQuery('#verificationcode').focus();
return false;
}
if (password.length == 0 || password == '请输入6-12位密码') {
alert("您的密码不能为空!");
jQuery('#password').focus();
return false;
}
if (password.length < 6 || password.length > 12) {
alert("密码为6-12位!");
jQuery('#password').focus();
return false;
}
if (rpassword.length == 0 || rpassword == '请重新输入密码') {
alert("重复密码不能为空!");
jQuery('#rpassword').focus();
return false;
}
if (rpassword != password) {
alert("两次输入密码不一致!");
jQuery('#rpassword').focus();
return false;
} jQuery.ajax({
type: "post",
url: "/KZH/Addkzhdata",
data: "phone=" + phone + "&code=" + code + "&password=" + password + "&type=" + type + "&t=" + new Date().toString(),
success: function (result) {
if (result == "0") {
alert("您的手机验证码不正确!");
jQuery('#verificationcode').focus();
return false;
}
else if (result == "1") {
jQuery('#phone').val("");
jQuery('#verificationcode').val("");
jQuery('#password').val("");
jQuery('#rpassword').val("");
alert("您的资料已提交,客服人员会尽快与您联系");
window.location.href = "http://www.jfinfo.com";
}
else if (result=="yes") {
$("#tc").show();
} },
error: function (result) {
alert("访问出错!");
}
});
} $(function(){
$("#tc a.close").click(function(){
$("#tc").hide();
})
}) document.onkeydown = function (event) {
var e = event || window.event || arguments.callee.caller.arguments[0];
if (e && e.keyCode == 13) { // enter 键
tj();
}
}; function getcode() {
var phone = jQuery('#phone').val();
if (phone.length == 0 || phone == '请输入您的手机号码') {
alert("您的手机号码不能为空!");
jQuery('#phone').focus();
return false;
}
if (phone.length > 0) {
var ab = /^(13[0-9]|15[0-9]|18[0-9])\d{8}$/;
if (ab.test(phone) == false) {
alert("您的手机号码不正确!");
jQuery('#phone').focus();
return false;
}
} jQuery.ajax({
type: "post",
url: "/KZH/Getcode",
data: "phone=" + phone + "&t=" + new Date().toString(),
success: function (rval) {
if (rval == "0") {
alert("您的资料已经提交过,客服人员会尽快与您联系!");
} else if (rval == "1") {
alert("信息已发送,请查收!");
var count = 60;
var countdown = setInterval(CountDown, 1000);
var timeShow = $(".hQBtn")
function CountDown() {
timeShow.removeAttr("disabled");
//timeShow.val(count + " 秒后重新发送");
timeShow.addClass("btn_hui").val(count + " 秒后重新获取").attr("disabled","true");
if (count == 0) {
timeShow.removeClass("btn_hui").val("获取验证码").removeAttr("disabled");
clearInterval(countdown);
}
count--;
}
}
},
error: function (result) {
alert("访问出错!");
}
});
}