移動端監聽輸入手機號以及判斷手機號有效

來源:互聯網
上載者:User

標籤:實現   query   下載   input   style   需求   1.7   test   round   

項目案例需求如,輸入/綁定正確的手機號才能下載軟體,輸入手機號發送驗證碼的功能等;

如下代碼可以實現準系統:

<!DOCTYPE html><html lang="en"><head>    <meta charset="utf-8">    <style>        .gray-btn{            background: #ccc;        }        .blue-btn{            background: #09f;        }    </style></head><body><input type="tel" name="mobile" id="getNum" value="" placeholder="填寫手機號碼" autocomplete=‘off‘/><input type="button" name="button" class="gray-btn downloadBtn" value="去下載**APP" disabled/><script src="jquery-1.7.2.min.js"></script><script>    //監聽輸入手機號    $(document).on(‘input propertychange‘,‘#getNum‘,function (e) {        if (e.type === "input" || e.orignalEvent.propertyName === "value") {            if(this.value.length == 11){                var myreg = /^1\d{10}$/;                if(!myreg.test(this.value)){                    common.tips({msg:‘請輸入正確手機號‘});                    return;                }                    $(‘.downloadBtn‘).removeClass(‘gray-btn‘).addClass(‘blue-btn‘);                $(‘.downloadBtn‘).attr("disabled", false);            }else{                $(‘.downloadBtn‘).addClass(‘gray-btn‘).removeClass(‘blue-btn‘);                $(‘.downloadBtn‘).attr("disabled", true);            }        }    })</script></body></html>

 

移動端監聽輸入手機號以及判斷手機號有效

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.