//js对象
var Index={
* 方法:初始化数据
*/
init : function()
{
} , ---注意这里有个逗号
/*
* 方法:加载资源
*/
loadResource : function(num,type)
{
}
};-----注意这里有个分号
jsp页面使用:
1、引用js;
2、使用:
Index.init();
Index.loadResource(2,10);
-----------------------------------
//js工具对象
var Utils = {
EMPTY : "",
/**
* 不为空:true; 为空 : false
*
* @param objectEntity
* @returns {Boolean}
*/
isNotEmpty : function(objectEntity) {
if (objectEntity == null || objectEntity == ''
|| typeof (objectEntity) == 'undefined'
|| objectEntity == undefined || 'null' == objectEntity) {
return false;
}
return true;
},
/**
* 为空:true; 不为空 : false
*
* @param objectEntity
* @returns {Boolean}
*/
isEmpty : function(objectEntity) {
if (objectEntity == null || objectEntity == ''
|| typeof (objectEntity) == 'undefined'
|| objectEntity == undefined || 'null' == objectEntity) {
return true;
}
return false;
},
// 校验是否为邮箱
isEmail : function(m) {
if ($.trim(m).length != 0) {
//reg =/^([a-zA-Z0-9]+[-|\-|_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[-|\-|_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
//reg = "\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*";
reg = new RegExp('\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*');
var r = m.match(reg);
if (r == null)
return false;
return true;
}
return false;
},
// 判断是否为日期,支持格式
isDate : function(t) {
if ($.trim(t).length != 0) {
var reg = /^(\d{4})(-|\/|\.)(\d{1,2})\2(\d{1,2})$|^\d{4}年\d{1,2}月\d{1,2}日$/;
var r = t.match(reg);
if (r == null)
return false;
return true;
}
return false;
},
//判断是否为有效的URL
isURL : function(url) {
var urlReg=/^((https|http|ftp|rtsp|mms):\/\/)?[A-Za-z0-9]+\.[A-Za-z0-9]+[\/=\?%\-&_~`@[\]\':+!]*([^<>\"\"])*$/;
if (!urlReg.test(url))
{
return false;
}
return true;
},
//判断是否满足电话号码格式,支持11位手机号码和带0的手机号码
//电话号码支持7、8位号码,同时支持带3-4位区号的号码
//样例:13520124512、014512451256、0731-1201214、021-78451210、7845784、89562312
isPhoneOrMobile : function(p) {
if ($.trim(p).length != 0) {
var reg = /(^[0-9]{3,4}\-[0-9]{7,8}$)|(^[0-9]{3,4}[0-9]{7,8}$)|(^[0-9]{7,8}$)|(^0{0,1}1[0-9]{10}$)/;
var r = p.match(reg);
if (r == null)
return false;
return true;
}
return false;
}
};