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調用阿里雲短信接口:https://www.cnblogs.com/pxblog/p/11982524.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM