JS发送短信验证码

<div>
<input type="tel" id="mobile" name="mobile" placeholder="输入手机号码" />
<button onclick="getSms();return false" id="yzmMsg">获取验证码</button>
</div>
<div>
<input type="text" id="captcha" name="captcha" placeholder="输入短信验证码" />
</div>

 

 

var i = 60;
        var smsback = "";
        function getSms(){
            var mobileReg = /^((13[0-9])|(14[5,7])|(15[0-3,5-9])|(17[0,3,5-8])|(18[0-9])|166|198|199|(147))\d{8}$/;
            var mobile = $("#mobile").val();
            if(!mobileReg.test(mobile)){
                layer.msg("请填写正确的手机号码");
                return;
            }
            if(i!=60){
                return;
            }
            $.ajax({
url:'send/msg',
data:{'mobile':mobile}, dataType:"json", type:"POST", success:function (data) { smsback = data.msgCode; alert(data.testCode);
changeMsg(); } }); } function changeMsg(){ if(i>0){ $("#yzmMsg").html(i+"秒后再次发送"); i--; setTimeout('changeMsg()',1000); }else{ $("#yzmMsg").html("获取验证码"); i=60; } }

 

 

JAVA调用阿里云短信接口:https://www.cnblogs.com/pxblog/p/11982524.html

posted @ 2019-03-14 12:01  yvioo  阅读(3642)  评论(0编辑  收藏  举报