ajax檢測用戶名密碼


<label class="col-sm-2 control-label font">用戶名</label>
                    <div class="col-sm-10">
                        <input type="text" class="form-control bt" name="uid" id="uid" placeholder="請設置用戶名"><span id="ts"></span>
<div class="form-group">
                <label class="col-sm-2 control-label font">手機號</label>
                    <div class="col-sm-10 ">
                        <input type="text" class="form-control bt" name="tel" id="tel" placeholder="可用於登錄" ><span id="sj"></span>
                    </div>
            </div><br/><br/><br/><br />
<script type="text/javascript">
$("#uid").blur(function()
{
    var uid = $(this).val();
    if(uid!="")//驗證是否為空
    {
        $.ajax(
            {
                url:"Xiugai_uid.php",
                data:{uid:uid},
                type: "POST",
                dataType:"TEXT",
                success: function(data)
                    {
                        if(data.trim()=="OK")
                        {
                            $("#ts").html("用戶名正確");
                            $("#ts").css("color","green");
                        }
                        else
                        {
                            $("#ts").html("用戶名錯誤");
                            $("#ts").css("color","red");
                        }
                    }
            });
    }
    else
    {
        alert("請填寫完整!");
    }
 
})
function checkMobile(str) {
      
    var  re = /^1\d{10}$/ //驗證是不是11位數字
    if (re.test(str)) {
          $("#sj").html("手機號碼格式正確");
          $("#sj").css("color","green");
    }
    else {
          $("#sj").html("手機號碼格式錯誤");
          $("#sj").css("color","red");
    }
}
$("#tel").blur(function(){
        var str = $(this).val();
        checkMobile(str);
})
 
    var uid = $("#uid").val()
    var tel = $("#tel").val()
    //if(tel!=""&&uid!="")
//  {
    $("button").click(function(){
        var uid = $("#uid").val()
        var tel = $("#tel").val()
        $.ajax({
             url:"Xiugai_yan.php",
             data:{uid:uid,tel:tel},
             type:"POST",
             dataType:"TEXT",
             success: function(data){
                 if(data.trim()=="ok")
                  {
                     window.location.href="xiugaiT.php";
                  }
                  else
                  {
                    alert("用戶名或手機號不匹配!");
                  }
     
                 }
             })
    });
</script>

 


免責聲明!

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



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