验证电话号码并延时60秒

        var wait = 60;
        function time(btn) {
            var txtTel = $('#txtTel').val();
            var isMobile = /^(?:13\d|15\d)\d{5}(\d{3}|\*{3})$/;
            var isPhone = /^((0\d{2,3})-)?(\d{7,8})(-(\d{3,}))?$/;

            if (!isMobile.test(txtTel) && !isPhone.test(txtTel)) {
                alert("请正确填写电话号码,例如:13415764179或0321-4816048");
                return false;
            }
            if (wait == 0) {
                btn.removeAttribute("disabled");
                btn.value = "免费获取验证码";
                wait = 60;

            } else {
                if (wait == 60) {
                    SendSmCode();
                }
                btn.setAttribute("disabled", true);
                btn.value = wait + "秒后重新获取验证码";
                wait--;
                setTimeout(function () {
                    time(btn);
                },
                1000)
            }
        }

        function SendSmCode() {

            alert("已发送");
        }

 

posted @ 2013-11-12 23:12  黑 瞳  阅读(370)  评论(0编辑  收藏  举报