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

jQuery插件formValidator自定義函數(shù)擴(kuò)展功能實(shí)例詳解

 更新時(shí)間:2015年11月25日 12:29:04   作者:一只小青蛙  
這篇文章主要介紹了jQuery插件formValidator自定義函數(shù)擴(kuò)展功能,結(jié)合實(shí)例形式分析了jQuery插件formValidator常見(jiàn)的各種判定與驗(yàn)證技巧,非常簡(jiǎn)單實(shí)用,需要的朋友可以參考下

本文實(shí)例講述了jQuery插件formValidator自定義函數(shù)擴(kuò)展功能的方法。分享給大家供大家參考,具體如下:

jQuery formValidator表單驗(yàn)證插件是什么?感興趣的讀者可參考《jQuery formValidator表單驗(yàn)證插件》以及本站其他相關(guān)文檔

此處省略若干文字。

實(shí)際項(xiàng)目中的表單應(yīng)用是多種多樣的,隨之而來(lái)的驗(yàn)證也是多變的,但Jquery formValidator為我們提供了自定義函數(shù)接口,個(gè)人認(rèn)為是其最主要的強(qiáng)大之處。廢話不多說(shuō),直接實(shí)例。

例一:座機(jī)和手機(jī),至少選其一,可以不選。

分析:這屬于組合驗(yàn)證,需要根據(jù)用戶選擇框體的不同進(jìn)行不同的驗(yàn)證條件。

知識(shí)點(diǎn):Jquery formvalidator提供了自定義函數(shù)接口為functionValidator({ fun: funname });

座機(jī)手機(jī)

$("#txtMobileTel,#txtContactTel").formValidator({ tipid: "txtMobileTelTip", onshow: "請(qǐng)?zhí)顚懭我环N聯(lián)系號(hào)碼", onfocus: "請(qǐng)輸入移動(dòng)電話或座機(jī)電話", oncorrect: "輸入正確!" }).functionValidator({ fun: allEmpty });
function allEmpty(val, elem) {
 if ($("#txtMobileTel").val() == "" && $("#txtContactTel").val() == "") {
  return '請(qǐng)輸入移動(dòng)電話或座機(jī)電話';
 }
 else {
  if ($("#txtMobileTel").val() != "" && $("#txtContactTel").val() != "") {
   if (($("#txtMobileTel").val()).search(/^(((13[0-9]{1})|(15[0-9]{1}))+\d{8})$/) != -1) {
    if (($("#txtContactTel").val()).search(/^(([0\+]\d{2,3}-)?(0\d{2,3})-)?(\d{7,8})(-(\d{3,}))?$/) != -1) { return true } else {
     return "座機(jī)電話格式錯(cuò)誤";
    }
   } else {
    return "移動(dòng)電話格式錯(cuò)誤";
   }
  } else {
   if ($("#txtMobileTel").val() != "") {
    if (($("#txtMobileTel").val()).search(/^(((13[0-9]{1})|(15[0-9]{1}))+\d{8})$/) != -1) { return true } else {
     return "移動(dòng)電話格式錯(cuò)誤";
    }
   }
   if ($("#txtContactTel").val() != "") {
    if (($("#txtContactTel").val()).search(/^(([0\+]\d{2,3}-)?(0\d{2,3})-)?(\d{7,8})(-(\d{3,}))?$/) != -1) { return true } else {
     return "座機(jī)電話格式錯(cuò)誤";
    }
   }
  }
};

例二:地區(qū)級(jí)聯(lián)下拉,當(dāng)不存在二級(jí)地區(qū)的下拉解除校驗(yàn)。

省市地區(qū)級(jí)聯(lián)

$("#ddlOne").formValidator({ onshow: "請(qǐng)選擇省市", onfocus: "省市必須選擇", oncorrect: "輸入正確" }).inputValidator({ min: 1, onerror: "請(qǐng)選擇有效的地區(qū)" }).functionValidator({ fun: city });
 $("#ddlTwo").formValidator({ onshow: "請(qǐng)選擇城市", onfocus: "城市必須選擇", oncorrect: "輸入正確" }).inputValidator({ min: 1, onerror: "請(qǐng)選擇有效的地區(qū)" });
function city(val, elem) {
 var a = "";
 $.getJSON("../Customer/Area.ashx?parentid=" + $("#ddlOne option:selected").val(), null, function(json) { 
  if (json[0].areacode == "0") {
   $("#ddlTwo").attr("disabled", true).unFormValidator(true); //解除校驗(yàn)
  }
  else {
   $("#ddlTwo").attr("disabled", false).unFormValidator(false); //恢復(fù)校驗(yàn)
  }
 });
}

常用驗(yàn)證:

整數(shù):

復(fù)制代碼 代碼如下:
$("#zs").formValidator({onshow:"請(qǐng)輸入整數(shù)",oncorrect:"謝謝你的合作,你的整數(shù)正確"}).regexValidator({regexp:"intege",datatype:"enum",onerror:"整數(shù)格式不正確"});

正整數(shù):

復(fù)制代碼 代碼如下:

$("#zzs").formValidator({onshow:"請(qǐng)輸入正整數(shù)",oncorrect:"謝謝你的合作,你的正整數(shù)正確"}).regexValidator({regexp:"intege1",datatype:"enum",onerror:"正整數(shù)格式不正確"});

負(fù)整數(shù):

復(fù)制代碼 代碼如下:

$("#fzs").formValidator({onshow:"請(qǐng)輸入負(fù)整數(shù)",oncorrect:"謝謝你的合作,你的負(fù)整數(shù)正確"}).regexValidator({regexp:"intege2",datatype:"enum",onerror:"負(fù)整數(shù)格式不正確"});

正數(shù):

復(fù)制代碼 代碼如下:

$("#zs1").formValidator({onshow:"請(qǐng)輸入正數(shù)",oncorrect:"謝謝你的合作,你的正數(shù)正確"}).regexValidator({regexp:"num1",datatype:"enum",onerror:"正數(shù)格式不正確"});

數(shù)字:

復(fù)制代碼 代碼如下:

$("#sz").formValidator({onshow:"請(qǐng)輸入數(shù)字",oncorrect:"謝謝你的合作,你的數(shù)字正確"}).regexValidator({regexp:"num",datatype:"enum",onerror:"數(shù)字格式不正確"});

負(fù)數(shù):

復(fù)制代碼 代碼如下:

$("#fs").formValidator({onshow:"請(qǐng)輸入負(fù)數(shù)",oncorrect:"謝謝你的合作,你的負(fù)數(shù)正確"}).regexValidator({regexp:"num2",datatype:"enum",onerror:"負(fù)數(shù)格式不正確"});

浮點(diǎn)數(shù):

$("#zfds").formValidator({onshow:"請(qǐng)輸入正浮點(diǎn)數(shù)",oncorrect:"謝謝你的合作,你的正浮點(diǎn)數(shù)正確"}).regexValidator({regexp:"decmal1",datatype:"enum",onerror:"正浮點(diǎn)數(shù)格式不正確"});
$("#ffds").formValidator({onshow:"請(qǐng)輸入負(fù)浮點(diǎn)數(shù)",oncorrect:"謝謝你的合作,你的負(fù)浮點(diǎn)數(shù)正確"}).regexValidator({regexp:"decmal2",datatype:"enum",onerror:"負(fù)浮點(diǎn)數(shù)格式不正確"});
$("#fffds").formValidator({onshow:"請(qǐng)輸入非負(fù)浮點(diǎn)數(shù)",oncorrect:"謝謝你的合作,你的非負(fù)浮點(diǎn)數(shù)正確"}).regexValidator({regexp:"decmal4",datatype:"enum",onerror:"非負(fù)浮點(diǎn)數(shù)格式不正確"});
$("#fzfds").formValidator({onshow:"請(qǐng)輸入非正浮點(diǎn)數(shù)",oncorrect:"謝謝你的合作,你的非正浮點(diǎn)數(shù)正確"}).regexValidator({regexp:"decmal5",datatype:"enum",onerror:"非正浮點(diǎn)數(shù)格式不正確"});

手機(jī):

復(fù)制代碼 代碼如下:

$("#sj").formValidator({onshow:"請(qǐng)輸入你的手機(jī)號(hào)碼",onfocus:"必須是13或15打頭哦",oncorrect:"謝謝你的合作,你的手機(jī)號(hào)碼正確"}).regexValidator({regexp:"mobile",datatype:"enum",onerror:"手機(jī)號(hào)碼格式不正確"});

座機(jī):

復(fù)制代碼 代碼如下:

$("#dh").formValidator({onshow:"請(qǐng)輸入國(guó)內(nèi)電話",onfocus:"例如:0577-88888888或省略區(qū)號(hào)88888888",oncorrect:"謝謝你的合作,你的國(guó)內(nèi)電話正確"}).regexValidator({regexp:"tel",datatype:"enum",onerror:"國(guó)內(nèi)電話格式不正確"});

郵箱:

復(fù)制代碼 代碼如下:

$("#email").formValidator({onshow:"請(qǐng)輸入你的email",onfocus:"請(qǐng)注意你輸入的email格式,例如:wzmaodong@126.com",oncorrect:"謝謝你的合作,你的email正確"}).regexValidator({regexp:"email",datatype:"enum",onerror:"email格式不正確"});

郵編:

復(fù)制代碼 代碼如下:

$("#yb").formValidator({onshow:"請(qǐng)輸入郵編",onfocus:"6位數(shù)字組成的哦",oncorrect:"謝謝你的合作,你的郵編正確"}).regexValidator({regexp:"zipcode",datatype:"enum",onerror:"郵編格式不正確"});

QQ:

復(fù)制代碼 代碼如下:

$("#qq").formValidator({onshow:"請(qǐng)輸入QQ號(hào)碼",oncorrect:"謝謝你的合作,你的QQ號(hào)碼正確"}).regexValidator({regexp:"qq",datatype:"enum",onerror:"QQ號(hào)碼格式不正確"});

身份證:

復(fù)制代碼 代碼如下:

$("#sfz").formValidator({onshow:"請(qǐng)輸入身份證",oncorrect:"謝謝你的合作,你的身份證正確"}).regexValidator({regexp:"idcard",datatype:"enum",onerror:"身份證格式不正確"});

字母:

復(fù)制代碼 代碼如下:

$("#zm").formValidator({onshow:"請(qǐng)輸入字母",oncorrect:"謝謝你的合作,你的字母正確"}).regexValidator({regexp:"letter",datatype:"enum",onerror:"字母格式不正確"});

大寫字母:

復(fù)制代碼 代碼如下:

$("#dxzm").formValidator({onshow:"請(qǐng)輸入大寫字母",oncorrect:"謝謝你的合作,你的大寫字母正確"}).regexValidator({regexp:"letter_u",datatype:"enum",onerror:"大寫字母格式不正確"});

小寫字母:

復(fù)制代碼 代碼如下:

$("#xxzm").formValidator({onshow:"請(qǐng)輸入小寫字母",oncorrect:"謝謝你的合作,你的小寫字母正確"}).regexValidator({regexp:"letter_l",datatype:"enum",onerror:"小寫字母格式不正確"});

希望本文所述對(duì)大家jQuery程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論