手机发送验证码

$(document).on('click','#getcode',function(){

    var tel = $('#tel').val();
    var _this = $('#getcode');
    var _this_html = _this.html();
    const numreg = /^\d/;
    const reg = /^1[3|4|5|6|7|8]\d{9}$/;

    if (numreg.test(_this_html)){
        return false;
    }

    if (reg.test(tel)) {     //验证手机号码规则
        let count = 60;
        let timer = setInterval(() => {
            count--;
            $(_this).html(count + 's重新获取');
            if (count === 0) {
                // $(_this).removeAttr('disabled');
                // $(_this).removeClass('disabled_btn');
                clearInterval(timer);
                $(_this).val('获取验证码');
            }
        }, 1000)
    } else {
        alert('请输入正确的手机号码')
    }
});

 

posted @ 2019-01-05 16:42  盘思动  阅读(201)  评论(0编辑  收藏  举报