70 lines
2.2 KiB
JavaScript
70 lines
2.2 KiB
JavaScript
//时间对象的格式化 eg:format="yyyy-MM-dd hh:mm:ss";
|
||
Date.prototype.format = function (format) {
|
||
var o = {
|
||
"M+": this.getMonth() + 1, // month
|
||
"d+": this.getDate(), // day
|
||
"h+": this.getHours(), // hour
|
||
"m+": this.getMinutes(), // minute
|
||
"s+": this.getSeconds(), // second
|
||
"q+": Math.floor((this.getMonth() + 3) / 3), // quarter
|
||
"S": this.getMilliseconds()
|
||
}
|
||
if (/(y+)/.test(format)) {
|
||
format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4
|
||
- RegExp.$1.length));
|
||
}
|
||
for (var k in o) {
|
||
if (new RegExp("(" + k + ")").test(format)) {
|
||
format = format.replace(RegExp.$1, RegExp.$1.length == 1
|
||
? o[k]
|
||
: ("00" + o[k]).substr(("" + o[k]).length));
|
||
}
|
||
}
|
||
return format;
|
||
};
|
||
|
||
// 扩展 easyui 验证规则
|
||
$.extend($.fn.validatebox.defaults.rules, {
|
||
numberic : { // 验证数字
|
||
validator : function(value) {
|
||
return /^[0-9]*$/i.test(value);
|
||
},
|
||
message : lang.PleaseInputDigital
|
||
},
|
||
ip : { // 验证IP地址
|
||
validator : function(value) {
|
||
var re = /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/;
|
||
return re.test(value);
|
||
},
|
||
message : lang.IPAFII
|
||
},
|
||
blwtext : { // 验证文本不能有特殊字符
|
||
validator : function(value) {
|
||
var re = /[`~!@#$%^&*()_\-+=<>?:"{}|,.\/;'\\[\]·~!@#¥%……&*()——\-+={}|《》?:“”【】、;‘’,。、]/im;
|
||
return !re.test(value);
|
||
},
|
||
message : "不能输入特殊字符"
|
||
}
|
||
});
|
||
|
||
// jQuery插件
|
||
// 将form表单的值序列化为json对象
|
||
(function ($) {
|
||
$.fn.serializeJson = function () {
|
||
var serializeObj = {};
|
||
var array = this.serializeArray();
|
||
var str = this.serialize();
|
||
$(array).each(function () {
|
||
if (serializeObj[this.name]) {
|
||
if ($.isArray(serializeObj[this.name])) {
|
||
serializeObj[this.name].push(this.value);
|
||
} else {
|
||
serializeObj[this.name] = [serializeObj[this.name], this.value];
|
||
}
|
||
} else {
|
||
serializeObj[this.name] = this.value;
|
||
}
|
||
});
|
||
return serializeObj;
|
||
};
|
||
})(jQuery);
|