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

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

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

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

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

此處省略若干文字。

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

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

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

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

座機手機

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

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

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

$("#ddlOne").formValidator({ onshow: "請選擇省市", onfocus: "省市必須選擇", oncorrect: "輸入正確" }).inputValidator({ min: 1, onerror: "請選擇有效的地區(qū)" }).functionValidator({ fun: city });
 $("#ddlTwo").formValidator({ onshow: "請選擇城市", onfocus: "城市必須選擇", oncorrect: "輸入正確" }).inputValidator({ min: 1, onerror: "請選擇有效的地區(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); //解除校驗
  }
  else {
   $("#ddlTwo").attr("disabled", false).unFormValidator(false); //恢復(fù)校驗
  }
 });
}

常用驗證:

整數(shù):

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

正整數(shù):

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

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

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

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

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

正數(shù):

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

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

數(shù)字:

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

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

負(fù)數(shù):

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

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

浮點數(shù):

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

手機:

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

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

座機:

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

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

郵箱:

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

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

郵編:

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

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

QQ:

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

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

身份證:

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

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

字母:

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

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

大寫字母:

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

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

小寫字母:

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

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

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

相關(guān)文章

最新評論