验证电话号码并延时60秒

2年前 (2022) 程序员胖胖胖虎阿
138 0 0
        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("已发送");
        }

 

版权声明:程序员胖胖胖虎阿 发表于 2022年11月5日 下午6:16。
转载请注明:验证电话号码并延时60秒 | 胖虎的工具箱-编程导航

相关文章

暂无评论

暂无评论...