欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

JS實(shí)現(xiàn)表單驗(yàn)證功能(驗(yàn)證手機(jī)號(hào)是否存在,驗(yàn)證碼倒計(jì)時(shí))

 更新時(shí)間:2016年10月11日 10:39:20   作者:danran68  
js實(shí)現(xiàn)表單驗(yàn)證功能,通過js代碼驗(yàn)證手機(jī)號(hào)是否存在驗(yàn)證碼倒計(jì)時(shí)功能,代碼簡單易懂非常不錯(cuò),具有參考借鑒價(jià)值,感興趣的朋友一起看看吧

廢話不多說直接上代碼

html代碼:

<form method="post" id="form_hroizon" enctype="multipart/form-data" action="/">
<input type="hidden" name="phoneTemplet" id="phoneTemplet">
<input type="hidden" name="regType" id="regType">
<div class="c-login-input">
<div class="form-group">
<label for="inputEmail3" class="label-control label-width120 pull-left t-r-f f16">手機(jī)號(hào)</label>
<div class="pull-left">
<input type="tel" autocomplete="off" class="input-control put-width440 j-telphone" id="inputtel" name="phones" placeholder="請(qǐng)輸入您的電話號(hào)碼" value="">
<span class="f12 red tel-msg"></span>
<div class="c-login-errtips" style="display:none;"></div>
</div>
</div>
<div class="form-group">
<label for="inputEmail3" class="label-control label-width120 pull-left t-r-f f16">登錄密碼</label>
<div class="pull-left">
<input type="password" class="input-control put-width440 fistpwd" id="inputpwd" name="password" placeholder="請(qǐng)輸入密碼" value="">
<span class="f12 red pwd-msg"></span>
</div>
</div>
<div class="form-group">
<label for="inputEmail3" class="label-control label-width120 pull-left t-r-f f16">驗(yàn)證碼</label>
<div class="pull-left">
<input type="tel" class="input-control put-with100 vericode" id="inputEmail3" name="code" placeholder="請(qǐng)輸入驗(yàn)證碼">
<input id="btnSendCode" type="button" value="免費(fèi)獲取驗(yàn)證碼" class="j-getcode f12 b-i-k btn code-btn c-p" />
<span class="f12 red code-msg"></span>
</div>
</div>
</div>
<div class="form-group">
<a class="j-sends" type="submit" name="submit" target="_self" href="javascript:void(0)">注冊(cè)</a>
</div>
</form>

JS代碼:

<script type="text/javascript">
$(function(){
$(".j-sends").click(function(){
var phones = $.trim($(".j-telphone").val());
var isMobile=/^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1}))+\d{8})$/;
if(!phones){
$('.tel-msg').text('請(qǐng)輸入手機(jī)號(hào)碼,不能為空');
return false;
}else if (!isMobile.test(phones)) {
$('.tel-msg').text('請(qǐng)輸入有效的手機(jī)號(hào)碼');
return false;
}else{
//手機(jī)號(hào)碼是否存在
$.ajax({
url : "/", //
type:"post",
dataType:"JSON",
data:{
phones: phones,
}, 
contentType:'application/json;charset=UTF-8', 
//async: false,
success:function(data){
if (data.flag == "1") { //
$('.tel-msg').html(data.errorInfo); //
return false;
}else{
$('.tel-msg').html(data.errorInfo); //可
}
},
error:function(){
}
}); 
}
})
//驗(yàn)證碼倒計(jì)時(shí) 
var InterValObj; //timer變量,控制時(shí)間 
var count = 30; //間隔函數(shù),1秒執(zhí)行 
var curCount;//當(dāng)前剩余秒數(shù) 
var code = ""; //驗(yàn)證碼 
var regType;
var phoneTemplet;
var codeLength = 4;//驗(yàn)證碼長度 
$(".code-btn").click(function(){
curCount = count; 
var phone=$.trim($(".j-telphone").val());//手機(jī)號(hào)碼 
var isMobile=/^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1}))+\d{8})$/;
var jtel = $(".j-telphone");
if(phone != "" && isMobile.test(phone) && phone.length==11){ 
//設(shè)置button效果,開始計(jì)時(shí) 
$("#btnSendCode").attr("disabled", "true"); 
$("#btnSendCode").val("請(qǐng)?jiān)? + curCount + "秒內(nèi)輸入驗(yàn)證碼"); 
InterValObj = window.setInterval(SetRemainTime, 1000); //啟動(dòng)計(jì)時(shí)器,1秒執(zhí)行一次 
//產(chǎn)生驗(yàn)證碼 
for (var i = 0; i < codeLength; i++) { 
code += parseInt(Math.random() * 9).toString(); 
} 
//向后臺(tái)獲驗(yàn)證碼 
$.ajax({ 
url : base + "/", 
type: "POST",
// dataType: "text", 
// data: "phones=" + phone + "&code=" + code, 
dataType: "JSON",
data:{
phones:phone,
code: code,
regType:"1",
phoneTemplet:"phone_uc"
},
success: function (data){
if(data.flag=="F"){
$(".code-msg").html(data.errorInfo); 
}else{
$(".code-msg").html(data.errorInfo);
}
} 
}); 
}else{ 
$('.tel-msg').text('請(qǐng)輸入有效的手機(jī)號(hào)碼'); 
} 
});
//timer處理函數(shù) 
function SetRemainTime() { 
if (curCount == 0) { 
window.clearInterval(InterValObj);//停止計(jì)時(shí)器 
$("#btnSendCode").removeAttr("disabled");//啟用按鈕 
$("#btnSendCode").val("重新發(fā)送驗(yàn)證碼"); 
code = ""; //清除驗(yàn)證碼。如果不清除,過時(shí)間后,輸入收到的驗(yàn)證碼依然有效 
} 
else { 
curCount--; 
$("#btnSendCode").val("請(qǐng)?jiān)? + curCount + "秒內(nèi)輸入驗(yàn)證碼"); 
} 
} 
})
</script>

以上所述是小編給大家介紹的JS實(shí)現(xiàn)表單驗(yàn)證功能(驗(yàn)證手機(jī)號(hào)是否存在,驗(yàn)證碼倒計(jì)時(shí)),希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!

相關(guān)文章

最新評(píng)論