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){
            changeMsg();
        }else{
            return;
        }
        $.ajax({
            url:"${base}/sendMsg.jspx",
data:{
"mobile":mobile
} dataType:"json", type:"POST", success:function (data) { smsback = data.msgCode; alert(data.testCode); } }); } function changeMsg(){ if(i>0){ $("#yzmMsg").html(i+"秒後再次發送"); i--; setTimeout('changeMsg()',1000); }else{ $("#yzmMsg").html("獲取驗證碼"); i=60; } }

  

JAVA調用阿里雲短信接口:http://www.javashuo.com/article/p-vuilwbuu-mr.htmljavascript

相關文章
相關標籤/搜索