$.extend($.fn.validatebox.defaults.rules, { CHS: { validator: function (value, param) { return /^[\u0391-\uFFE5]+$/.test(value); }, message: '請輸入漢字' }, ZIP: { validator: function (value, param) { return /^[1-9]\d{5}$/.test(value); }, message: '郵政編碼不存在' }, email: { validator: function (value, param) { return /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((\.[a-zA-Z0-9_-]{2,3}){1,2})$/.test(value); }, message: '郵箱格式有誤' }, QQ: { validator: function (value, param) { return /^[1-9][0-9]{4,9}$/.test(value); }, message: 'QQ號碼不正確' }, mobile: { validator: function (value, param) { return /^(0?(13[0-9]|15[012356789]|18[0-9]|14[57])[0-9]{8})$/.test(value)||/^(0?(13[0-9]|15[012356789]|18[0-9]|14[57])[0-9]{8}\/0?(13[0-9]|15[012356789]|18[0-9]|14[57])[0-9]{8})$/.test(value); }, message: '手機號碼不正確' }, phone: { validator: function (value, param) { return /^(\+\d+)?(\d{3,4}\-?)?\d{7,8}$/.test(value); }, message: '座機號碼不正確' }, mobileorphone: { validator: function (value, param) { return /^((\+\d+)?(\d{3,4}\-?)?\d{7,8})|(0?(13[0-9]|15[012356789]|18[0-9]|14[57])[0-9]{8})$/.test(value); }, message: '電話號碼不正確' }, fax: { validator: function (value, param) { return /^(\d{3,4}-)?\d{7,8}$/.test(value); }, message: '傳真號碼不正確' }, loginName: { validator: function (value, param) { return /^[\u0391-\uFFE5\w]+$/.test(value); }, message: '登陸名稱只容許漢字、英文字母、數字及下劃線。' }, safepass: { validator: function (value, param) { return safePassword(value); }, message: '密碼由字母和數字組成,至少6位' }, equalTo: { validator: function (value, param) { alert(param); return value == $(param[0]).val(); }, message: '兩次輸入的字符不一致' }, equalOrGreatTo: { validator: function (value, param) { return value >= $(param[0]).val(); }, message: '本次輸入的字符和上次比較應該相同或者更大' }, number: { validator: function (value, param) { return isNumber(value); }, message: '請輸入正整數字' }, isNumber: { validator: function (value, param) { return /^[\-]?\d+([\.]?[\d]{1,})?$/.test(value); }, message: '請輸入數字' }, Char: { validator: function (value, param) { return /^[a-zA-Z]+$/.test(value); }, message: '請輸入英文字母' }, numberAndChar: { validator: function (value, param) { return /^[a-zA-Z0-9]+$/.test(value); }, message: '請輸入數字或英文字母' }, stringsDou: { validator: function (value, param) { return /^[a-zA-Z0-9,]+$/.test(value); }, message: '請輸入數字或英文字母' }, numberCharAndChs: { validator: function (value, param) { return /^[a-zA-Z0-9\u0391-\uFFE5]+$/.test(value); }, message: '請輸入數字或英文字母或漢字' }, stringsDouT: {//包含小數點 add by mengxin 2014-11-13 validator: function (value, param) { return /^[a-zA-Z0-9.\u0391-\uFFE5]+$/.test(value); }, message: '請輸入數字或英文字母' }, idcard: { validator: function (value, param) { return idCard(value); }, message:'請輸入正確的身份證號碼' }, numberDouble: { validator: function (value, param) { if (undefined==param) { return isNumber(value); } var pattern = new RegExp("^[1-9]{1}\\d*([\\.]{1}[\\d]{1,"+param+"})?$|^0$|^[0]{1}[\\.]{1}[\\d]{1,"+param+"}$"); return pattern.test(value); }, message:'請輸入小數或整數,小數點後保留{0}位' }, exRateHL: { validator: function (value, param) { if (undefined==param) { return false; } var pattern = new RegExp("^[1-9]{0,"+param[0]+"}([\\.]{1}[\\d]{0,"+(param[1]-1)+"})?[1-9]$|^[0]{1}[\\.]{1}[\\d]{0,"+(param[1]-1)+"}[1-9]$"); return pattern.test(value); }, message:'匯率格式爲小數點前最多1-{0}位,小數點後保留{1}位,最後一位不可爲0' }, isNotChinese: { validator: function (value, param) { return /[^\u4e00-\u9fa5]+$/.test(value); }, message:'請輸入非中文字符' }, isString: { //漢字、英文、數字 、下滑線、橫線、點、空格、逗號 validator: function (value, param) { return /^[\u0391-\uFFE5\w\s-\.\,]+$/.test(value); }, message:'輸入內容含有非法字符' }, isPercent: { //驗證百分數 validator: function (value, param) { return /^[\-]?\d+([\.]?[\d]{1,})?\%$/.test(value); }, message:'請輸入百分數' }, isNotSelect: { validator: function (value, param) { return isSelect(value); }, message:'請選擇下拉選項' }, date:{ validator: function (value, param) { return /^((\d{2}(([02468][048])|([13579][26]))[\-\/\s]?((((0?[13578])|(1[02]))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\-\/\s]?((0?[1-9])|([1-2][0-9])))))|(\d{2}(([02468][1235679])|([13579][01345789]))[\-\/\s]?((((0?[13578])|(1[02]))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\-\/\s]?((0?[1-9])|(1[0-9])|(2[0-8]))))))(\s(((0?[0-9])|([1-2][0-3]))\:([0-5]?[0-9])((\s)|(\:([0-5]?[0-9])))))?$/.test(value); }, message:'請輸入正確的日期格式' }, date_yyyy_mm:{ validator: function (value, param) { return /^\b[1-3]\d{3}(-|\/)(0[1-9]|1[0-2])$/.test(value); }, message:'請輸入格式爲yyyy-MM(2014-01)' }, date_yyyy_mm_dd:{ validator: function (value, param) { return /^\b[1-3]\d{3}(-|\/)(0[1-9]|1[0-2])(-|\/)(0[1-9]|1[0-9]|2[0-9]|3[0-1])$/.test(value); }, message:'請輸入格式爲yyyy-MM-dd(2014-01-01)' }, date_yyyy_mm_dd_hh_mm :{ validator: function (value, param) { return /^\b[1-3]\d{3}(-|\/)(0[1-9]|1[0-2])(-|\/)(0[1-9]|1[0-9]|2[0-9]|3[0-1])\s((0?[0-9])|(1[0-9]|2[0-3]))\:([0-5]?[0-9])$/.test(value); }, message:'請輸入格式爲yyyy-MM-dd hh:mm(2014-01-01 00:00)' }, comparedate : {/* 比較大小 */ validator : function(value, param) { var msg = param[1]; var startDate = new Date(Date.parse($('#'+param[0]).datebox("getValue").replace(/-/g, "/"))); var endDate = new Date(Date.parse(value.replace(/-/g, "/"))); if(startDate.getTime() < endDate.getTime()){ return true; } else { $.fn.validatebox.defaults.rules.comparedate.message = msg; return false; } }, message : '該輸入項爲必輸項' }, compare : {/* 比較大小 */ validator : function(value, param) { var msg = param[2]; var expression = param[1]; var cv = parseFloat($('#'+param[0]).val()); //比較值 value = parseFloat(value); if(expression == "\>"){ if(value > cv){ return true; } else { $.fn.validatebox.defaults.rules.compare.message = msg; return false; } }else if(expression == "\>="){ if(value >= cv){ return true; } else { $.fn.validatebox.defaults.rules.compare.message = msg; return false; } } else if(expression == "\<"){ if(value < cv){ return true; } else { $.fn.validatebox.defaults.rules.compare.message = msg; return false; } } else if(expression == "\<="){ if(value <= cv){ return true; } else { $.fn.validatebox.defaults.rules.compare.message = msg; return false; } } else { if(value == cv){ return true; } else { $.fn.validatebox.defaults.rules.compare.message = msg; return false; } } }, message : '該輸入項爲必輸項' }, CJH:{//車架號驗證 validator: function (value, param) { if (value.length == 0) { return false; } var result = $.ajax({ type: "POST",//http請求方式 url:purl+'cjhValidator.dh?key=checkCJH', //服務器段url地址 data:{CJH:value}, //發送給服務器段的數據 dataType: "json", //告訴JQuery返回的數據格式 async: false }).responseText; result = JSON.parse(result); if (result.success == false) { $.fn.validatebox.defaults.rules.CJH.message = result.msg; return false; } else { return true; } }, message:'該輸入項爲必輸項' }, checklength: { validator: function (value, param) { if (value.length != param[0]) { $.fn.validatebox.defaults.rules.checklength.message = param[1]+'的長度必須爲'+param[0]+'位'; return false; }else{ return true; } } } }); var isSelect=function (value){ if(value.indexOf("請選擇")>-1) return false; return true; }; var isNumber = function (value) { return /^\d+$/.test(value); }; var safePassword = function (value) { return !(/^(([A-Z]*|[a-z]*|\d*|[-_\~!@#\$%\^&\*\.\(\)\[\]\{\}<>\?\\\/\'\"]*)|.{0,5})$|\s/.test(value)); }; var idCard = function (value) { if (value.length == 18 && 18 != value.length) return false; var number = value.toLowerCase(); var d, sum = 0, v = '10x98765432', w = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2], a = '11,12,13,14,15,21,22,23,31,32,33,34,35,36,37,41,42,43,44,45,46,50,51,52,53,54,61,62,63,64,65,71,81,82,91'; var re = number.match(/^(\d{2})\d{4}(((\d{2})(\d{2})(\d{2})(\d{3}))|((\d{4})(\d{2})(\d{2})(\d{3}[x\d])))$/); if (re == null || a.indexOf(re[1]) < 0) return false; if (re[2].length == 9) { number = number.substr(0, 6) + '19' + number.substr(6); d = ['19' + re[4], re[5], re[6]].join('-'); } else d = [re[9], re[10], re[11]].join('-'); if (!isDateTime.call(d, 'yyyy-MM-dd')) return false; for (var i = 0; i < 17; i++) sum += number.charAt(i) * w[i]; return (re[2].length == 9 || number.charAt(17) == v.charAt(sum % 11)); }; var isDateTime = function (format, reObj) { format = format || 'yyyy-MM-dd'; var input = this, o = {}, d = new Date(); var f1 = format.split(/[^a-z]+/gi), f2 = input.split(/\D+/g), f3 = format.split(/[a-z]+/gi), f4 = input.split(/\d+/g); var len = f1.length, len1 = f3.length; if (len != f2.length || len1 != f4.length) return false; for (var i = 0; i < len1; i++) if (f3[i] != f4[i]) return false; for (var i = 0; i < len; i++) o[f1[i]] = f2[i]; o.yyyy = s(o.yyyy, o.yy, d.getFullYear(), 9999, 4); o.MM = s(o.MM, o.M, d.getMonth() + 1, 12); o.dd = s(o.dd, o.d, d.getDate(), 31); o.hh = s(o.hh, o.h, d.getHours(), 24); o.mm = s(o.mm, o.m, d.getMinutes()); o.ss = s(o.ss, o.s, d.getSeconds()); o.ms = s(o.ms, o.ms, d.getMilliseconds(), 999, 3); if (o.yyyy + o.MM + o.dd + o.hh + o.mm + o.ss + o.ms < 0) return false; if (o.yyyy < 100) o.yyyy += (o.yyyy > 30 ? 1900 : 2000); d = new Date(o.yyyy, o.MM - 1, o.dd, o.hh, o.mm, o.ss, o.ms); var reVal = d.getFullYear() == o.yyyy && d.getMonth() + 1 == o.MM && d.getDate() == o.dd && d.getHours() == o.hh && d.getMinutes() == o.mm && d.getSeconds() == o.ss && d.getMilliseconds() == o.ms; return reVal && reObj ? d : reVal; function s(s1, s2, s3, s4, s5) { s4 = s4 || 60, s5 = s5 || 2; var reVal = s3; if (s1 != undefined && s1 != '' || !isNaN(s1)) reVal = s1 * 1; if (s2 != undefined && s2 != '' && !isNaN(s2)) reVal = s2 * 1; return (reVal == s1 && s1.length != s5 || reVal > s4) ? -10000 : reVal; } };