1. 程式人生 > >使用者名稱、密碼、手機號驗證,驗證碼獲取,勾選協議

使用者名稱、密碼、手機號驗證,驗證碼獲取,勾選協議

<script type="text/javascript">
function CheckLogin(obj){
    if(obj.username.value=='')
    {
        alert('請輸入使用者名稱');
        obj.username.focus();
        return false;
    }
    if(obj.password.value=='')
    {
        alert('請輸入登入密碼');
        obj.password.focus();
        return false;
    }
    if(obj.loginauth!=null)
    {
        if(obj.loginauth.value=='')
        {
            alert('請輸入認證碼');
            obj.loginauth.focus();
            return false;
        }
    }
    if(obj.key!=null)
    {
        if(obj.key.value=='')
        {
            alert('請輸入驗證碼');
            obj.key.focus();
            return false;
        }
    }       
    return true;
}  
</script>
<script type="text/javascript">
function vc() {
    var myreg = /^[1][3,4,5,7,8][0-9]{9}$/;
    if(!myreg.test($("#phone").val()))
    {
        alert('請輸入有效的手機號碼!');
        return false;
    }
    var uname = /^[\u4E00-\u9FA5]{2,4}$/;
    if(!uname.test($("#name").val()))
    {
        alert('請輸入2-4位漢字姓名');
        return false;
    }
 callback();
}
function sentcode()
{
    var myreg = /^[1][3,4,5,7,8][0-9]{9}$/;
    if(!myreg.test($("#phone").val()))
    {
        alert('請輸入有效的手機號碼!');
        return false;
    }else{
        $.ajax({
        url: "../knowtree/testfunction.php",
        data: {
            tele:$("#phone").val(),
            action: "Teletest",
         },
         dataType: "text",
         type: 'POST',
         timeout: 10000,
         error: function () {
          alert("伺服器超時");
          },
          success: function (data1) {
              if(data1)
                {
                    $.ajax({
                        url: "../dysms/sendSms.php",
                        data: {
                        tele:$("#phone").val()
                        },
                        dataType: "text",
                        type: 'POST',
                        timeout: 10000,
                        error: function () {
                        alert("伺服器超時");
                        },
                        success: function (data) {
                            if(data)
                            {
                                document.getElementById('code1').value=data;
                            } else {
                                  document.getElementById('code1').value=0;
                            }
                        }
                    });
                }
                else
                {
                    alert("該手機號已經註冊,請返回登入");
                }
            }
        });
    }
}
//驗證碼初倒計時
var countdown=60; 
function sendemail(){
    var obj = $("#btn");
    settime(obj);
    sentcode();
}
function settime(obj) { //傳送驗證碼倒計時
    if (countdown == 0) { 
        obj.attr('disabled',false); 
        //obj.removeattr("disabled"); 
        obj.val("免費獲取驗證碼");
        countdown = 60; 
        return;
    } else { 
        obj.attr('disabled',true);
        obj.val("重新發送(" + countdown + ")");
        countdown--; 
    } 
    setTimeout(function() { 
        settime(obj) 
    },1000); 
}
/*勾選協議*/
function agree(){
    if(document.getElementById("cb").checked){
      document.getElementById("submit").disabled=false;
      document.getElementById("submit").style="background:";
    }
    else{
      document.getElementById("submit").disabled="disabled";
      document.getElementById("submit").style="background:#888";
      alert('請閱讀並勾選《國鳴助學助教系統使用協議》');      
    }
}     
</script>
<form name='feedback' method='post' enctype='multipart/form-data' action='newstudent.php' onsubmit="return vc()">
    <input type="hidden" name="enews" value="wxAddstudent">
    <input type="hidden" name="open_id" value="<?=$openid?>">
    <input type="hidden" id="code1" name="code1" value="<?=1234?>">
    <input type="hidden" name="adminwindow" value="0" checked>
    <div class="label1"><input name="student" type="text" id="name" placeholder="學生姓名" /></div>
    <div class="label1"><input name="telephone" id="phone"  placeholder="手機號" /></div>
    <div class="label1">
        <div class="div1">
            <input name="code" id="code" type="text" class="input4" placeholder="驗證碼"/>
            <input type="button" class="input5" id="btn" value="獲取驗證碼" onclick="sendemail()" />
        </div>
    </div>
    <div>
        <input type="checkbox" onclick="agree();" name="clause" id="cb" checked /><label for="cb">&nbsp;&nbsp;我已閱讀並接受以下條款:</label><br /><a href="./clause.html" style=" color:#1d8fe1">《國鳴助學助教系統使用協議》</a><br /><br />
    </div>    
    <div class="label2"><input type="submit" value="立即註冊" /></div>
</form>