$.extend($.fn.validatebox.defaults.rules, {
//验证汉字
CHS: {
validator: function (value) {
return /^[\u0391-\uFFE5]+$/.test(value);
},
message: '只能输入汉字'
},
//固定电话或手机号
mobileOrTele: {//value值为文本框中的值
validator: function (value) {
var reg = /(\d{11})|^((\d{7,8})|(\d{4}|\d{3})-(\d{7,8})|(\d{4}|\d{3})-(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1})|(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1}))$/;
return reg.test(value);
},
message: '输入固定电话或手机号码格式不准确.'
},
//移动手机号码验证
mobile: {//value值为文本框中的值
validator: function (value) {
var reg = /^1[3|4|5|8|9]\d{9}$/;
return reg.test(value);
},
message: '输入手机号码格式不准确.'
},
checkName : {//value值为文本框中的值
validator: function (value) {
var reg = /^1[3|4|5|8|9]\d{9}$/;
var regx = /^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$/;
if(reg.test(value) || regx.test(value)){
return true;
}
return false;
},
message: '请输入正确的手机号或邮箱号.'
},
//数字验证
numberV : {
validator: function (value) {
var reg = /^\d{1,10}$/;
return reg.test(value);
},
message: '输入编号格式不准确.请输入数字类型'
},
numberVs : {
validator: function (value) {
var reg = /^[\d]{7,7}$/;
return reg.test(value);
},
message: '请输入长度为7的数字类型'
},
cardNumber : {
validator: function (value) {
var reg = /^[\d]{1,20}$/;
return reg.test(value);
},
message: '您输入的不是纯数字'
},
//国内邮编验证
zipcode: {
validator: function (value) {
var reg = /^[1-9]\d{5}$/;
return reg.test(value);
},
message: '邮编必须是非0开始的6位数字.'
},
//用户账号验证(只能包括 _ 数字 字母)
account: {//param的值为[]中值
validator: function (value, param) {
if (value.length < param[0] || value.length > param[1]) {
$.fn.validatebox.defaults.rules.account.message = '用户名长度必须在' + param[0] + '至' + param[1] + '范围';
return false;
} else {
if (!/^[\w]+$/.test(value)) {
$.fn.validatebox.defaults.rules.account.message = '用户名只能数字、字母、下划线组成.';
return false;
} else {
return true;
}
}
}, message: ''
},
telphone: {
validator: function(value,param){
return /^\d{3}-\d{7,8}|\d{4}-\d{7,8}$/.test(value);
},
message: '号码格式不正确,如071-12345678或0710-1234567'
},
money: {
validator: function(value,param){
return /^\d{0,15}\.{0,1}(\d{1,2})?$/.test(value);
},
message: '最多两位小数'
},
cardNo: {
validator: function(value,param){
val = value.length;
return val >= 10 && val <= 20;
},
message: '结算账号应为10-20位.'
},
idcard: {
validator: function (value, param) {
return idCard(value);
},
message:'请输入正确的身份证号码'
},
IDNumber: {
validator: function(value,param){
val = value.length;
return val == 15 || val == 18;
},
message: '身份证号应为15或18位.'
},
areaCode: {
validator: function (value,param) {
var reg = /^\d{4}$/;
//alert("areaCode valid:"+reg.test(value));
return reg.test(value);
},
message: '请输入长度为4的数字类型区号,不足4位的前面补0'
}
});
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));
}