成人精品一区二区三区中文字幕-成人精品一区二区三区-成人精品一级毛片-成人精品亚洲-日本在线视频一区二区-日本在线视频免费

導航首頁 ? 技術(shù)教程 ? jQuery插件formValidator自定義函數(shù)擴展功能實例詳解
全站頭部文字 我要出現(xiàn)在這里
jQuery插件formValidator自定義函數(shù)擴展功能實例詳解 634 2024-03-19   

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

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

此處省略若干文字。

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

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

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

知識點: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}-)?(0d{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}-)?(0d{2,3})-)?(d{7,8})(-(d{3,}))?$/) != -1) { return true } else {
     return "座機電話格式錯誤";
    }
   }
  }
};

例二:地區(qū)級聯(lián)下拉,當不存在二級地區(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); //恢復校驗
  }
 });
}

常用驗證:

整數(shù):

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

正整數(shù):

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

負整數(shù):

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

正數(shù):

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

數(shù)字:

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

負數(shù):

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

浮點數(shù):

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

手機:

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

座機:

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

郵箱:

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

郵編:

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

QQ:

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

身份證:

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

字母:

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

大寫字母:

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

小寫字母:

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

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



主站蜘蛛池模板: 野兽罪人电影免费观看| 不回微信判30年图片| 好茶叶排名前十名| 许半夏电视剧在线观看| 艳窟神探| 孕妇电视剧| 非法制裁| 邓伦是石家庄哪里的| 我的漂亮的朋友| 许华升公个人资料身高多少| 欧美变态sososo另类| 镇魂街第三季| jenna haze| 张俪写真集照片| 妻子的秘密在线| 电影《斯宾塞》| 与心有关的成语| 马修·麦克费登| 中国汉字大全20000个| 山下大辉| 德爱白金奶粉| 我的奇妙男友2| 爱欲1990未删减版播放| 裸体小男孩| 电影《波丽露》免费观看| 尘埃落定剧情| 美人鱼的电影| xmx| 上门女婿电视剧演员| 山上的小屋 残雪原文| 刀郎歌曲简谱| 禁忌爱情| 思想认识不到位,重视程度不够| 电影频道直播| 情欲狂欢电影| 教育向美而生读书心得体会| 《眷恋》电影在线观看免费| 1988年英国的白蛇传说| 小数加减法100道题| 演员李崇霄的个人资料| 新奥特曼2|

!!!站長長期在線接!!!

網(wǎng)站、小程序:定制開發(fā)/二次開發(fā)/仿制開發(fā)等

各種疑難雜癥解決/定制接口/定制采集等

站長微信:lxwl520520

站長QQ:1737366103