亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

jquery+正則實(shí)現(xiàn)統(tǒng)一的表單驗(yàn)證

 更新時(shí)間:2015年09月20日 10:24:37   作者:點(diǎn)滴  
表單驗(yàn)證一直很繁瑣,特別是大點(diǎn)的表單,如果每個(gè)input都去單獨(dú)寫驗(yàn)證簡(jiǎn)直要寫死人,最近寫了一小段js統(tǒng)一的驗(yàn)證表單內(nèi)容是否正確。需要的朋友可以參考下

表單驗(yàn)證一直很繁瑣,特別是大點(diǎn)的表單,如果每個(gè)input都去單獨(dú)寫驗(yàn)證簡(jiǎn)直要寫死人,最近寫了一小段js統(tǒng)一的驗(yàn)證表單內(nèi)容是否正確。

使用這段代碼就不再需要對(duì)每個(gè)input寫格式判斷,只需要將正確格式的正則表達(dá)式寫在datatype里就可以了,提交表單按鈕也只需要綁定checkForm函數(shù)就可以了。

大家有什么建議可以評(píng)論一下

<input type="text" datatype=“正則”/>

//表單驗(yàn)證
//點(diǎn)擊下一步事件
function checkForm(form){
var success = true;
$("."+form+" input").each(function(){
var $that = $(this);
var dataType = eval($that.attr("dataType"));
if(dataType!=undefined){
if($that.val().match(dataType)){
$that.removeClass("borderRed");
}else{
$that.focus();
$that.addClass("borderRed");
success = false;
return false;
}
}
})
return success;
}

//給每個(gè)帶有datatype屬性的標(biāo)簽綁定blur focus事件

$(document).on("blur","input",function(){
var $that = $(this);
var dataType = eval($that.attr("dataType"));
if(dataType!=undefined){
if($that.val().match(dataType)){
$that.removeClass("borderRed");
}else{
$that.addClass("borderRed");
}
}
})
$(document).on("focus","input",function(){
$(this).removeClass("borderRed");
});

以上內(nèi)容給大家分享了jquery+正則實(shí)現(xiàn)統(tǒng)一的表單驗(yàn)證,希望大家喜歡。

相關(guān)文章

最新評(píng)論