jquery validate自定義驗證方法

2021-06-21 23:01:34 字數 2159 閱讀 8597

/* 追加自定義驗證方法 */

// 身份證號碼驗證

jqry.validator.addmethod(「idcardno」, function(val, element) , 」請正確輸入身份證號碼」);

//字母數字

jqry.validator.addmethod(「alnum」, function(val, element) , 」只能包括英文本母和數字」);

// 手機號碼驗證

jqry.validator.addmethod(「cellphone」, function(val, element) )$/.test(val));

}, 」請正確填寫手機號碼」);

// **號碼驗證

jqry.validator.addmethod(「telephone」, function(val, element) -?)?\d$/g;

return this.optional(element) || (tel.test(val));

}, 」請正確填寫**號碼」);

// 漢字

jqry.validator.addmethod(「chcharacter」, function(val, element) , 」請輸入漢字」);

/*** 身份證號碼驗證**/

function isidcardno(num) 

// check and set val

for(i=0;i 』9′) && (i != 17))  else if (i < 17) 

}if (intstrlen == 18) 

// calculate the sum of the prod ts

for(i=0;i<17;i++) 

// calculate the check digit

intcheckdigit = paritybit[lngprod t % 11];

// check last digit

if (vararray[17] != intcheckdigit) 

}else

}return tr;

}/**

* 判斷是否為「yyyymm」式的時期**/

function isdate6(sdate) $/.test(sdate)) 

var year, month, day;

year = sdate.s string(0, 4);

month = sdate.s string(4, 6);

if (year < 1700 || year > 2500) return false

if (month < 1 || month > 12) return false

return tr

}/**

* 判斷是否為「yyyymmdd」式的時期**/

function isdate8(sdate) $/.test(sdate)) 

var year, month, day;

year = sdate.s string(0, 4);

month = sdate.s string(4, 6);

day = sdate.s string(6, 8);

var iamonthdays = [31,28,31,30,31,30,31,31,30,31,30,31]

if (year < 1700 || year > 2500) return false

if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) iamonthdays[1]=29;

if (month < 1 || month > 12) return false

if (day < 1 || day > iamonthdays[month - 1]) return false

return tr

}自帶驗證規則

function validateform()/register/checkemail"

},nickname:,

gender:,

signature : ,

// password: ,

// confirm_password: ,

validatecode:

},messages:

},});

}

jquery validate 校驗心得

1.rule 裡面的設定的各個項是以name 做為關鍵字,莫以id做為唯一值。謹記 2.jquery.validator.format 的使用列子 button click function this is alert str str jquery.validator.format str,worl...

jQuery Validate外掛程式使用

這幾天一直在接觸驗證方面的工作,jquery validate是乙個比較常用的驗證外掛程式,說一下心得吧。效果圖類似 說乙個簡單的,現在需求是模板編號只能是正整數數字。控制項 如下 模板編號 接下來就是使用jquery了,第一步肯定是匯入js庫了,這個不用說,第二步開始寫js 解釋一下吧,首先jqu...

jQuery Validate 觸發機制

lang en charset utf 8 titletitle src jquery 1.11.2.js script src jquery.validate.min.js script document ready function 15 0 9 18 0 9 d test value 請正確填...