1 var JavaScriptCommon = { /*身份证号码校验*/ VerifyID: function (socialNo) { if (socialNo == "") { return (false); } && socialNo.length != ) { return (false); } : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : "国外" }; , ))] == null) { return (false); } ) { pattern = /^\d{}$/; if (pattern.exec(socialNo) == null) { return (false); } , )); , ); , )); switch (month) { ) { return false; } ) { return false; } == && birth % != ) || birth % == ) { ) { ) { return false; } } break; default: return false; } || nowYear - parseInt(birth) > ) { return false; } return (true); } , , , , , , , , , , , , , , , , , ); ; ; ; ; i < ; ++i) { ') { return (false); } '; } lSum += nNum * Wi[i]; } ) == ) == * Wi[]; } ) < ) > ') { return (false); } ) - ]; } ) == ) { return true; } else { return (false); } }, /*手机号码校验*/ isMobile: function (a) { []\d{}$/).test(a); }, //乘法函数,用来得到精确的乘法结果 //说明:javascript的乘法结果会有误差,在两个浮点数相乘的时候会比较明显。这个函数返回较为精确的乘法结果。 //调用:accMul(arg1,arg2) //返回值:arg1乘以arg2的精确结果 accMul: function (arg1, arg2) { , s1 = arg1.toString(), s2 = arg2.toString(); ].length } catch (e) { } ].length } catch (e) { } , m); }, //除法函数,用来得到精确的除法结果 //说明:javascript的除法结果会有误差,在两个浮点数相除的时候会比较明显。这个函数返回较为精确的除法结果。 //调用:accDiv(arg1,arg2) //返回值:arg1除以arg2的精确结果 accDiv: function (arg1, arg2) { , t2 = , r1, r2; ].length } catch (e) { } ].length } catch (e) { } with (Math) { r1 = Number(arg1.toString().replace(".", "")); r2 = Number(arg2.toString().replace(".", "")); , t2 - t1); if (result == Infinity) { result = ; } return result; } }, //加法函数,用来得到精确的加法结果 //说明:javascript的加法结果会有误差,在两个浮点数相加的时候会比较明显。这个函数返回较为精确的加法结果。 //调用:accAdd(arg1,arg2) //返回值:arg1加上arg2的精确结果 accAdd: function (arg1, arg2) { var r1, r2, m; ].length } } ].length } } m = Math.pow(, Math.max(r1, r2)); return (arg1 * m + arg2 * m) / m; }, // 减法函数 accSub: function accSub(arg1, arg2) { )); }, GetRequest: function () { var url = location.search; //获取url中"?"符后的字串 var theRequest = new Object(); ) { ); strs = str.split("&"); ; i < strs.length; i++) { theRequest[strs[i].split(]] = (strs[i].split(]); } } return theRequest; } }; /* String */ String.prototype.IsEmpty = function () { return this == null || typeof (this) == "undefined" || this == ""; } String.prototype.IsNumber = function () { -]+$/; return reg.test(this); } String.prototype.IsIdentity = function () { return JavaScriptCommon.VerifyID(this); } String.prototype.IsDecimal = function () { -]+(.[-]{,})?$/; return reg.test(this); } String.prototype.IsEnglish = function () { var reg = /^C_\w+$/; return reg.test(this); } //添加验证0~1之间小数 String.prototype.isPercernt = function () { ]+(.[-]{,})?$|$/; return reg.test(this); } String.prototype.IsDate = function () { var regex = new RegExp("^(?:(?:([0-9]{4}(-|\/)(?:(?:0?[1,3-9]|1[0-2])(-|\/)(?:29|30)|((?:0?[13578]|1[02])(-|\/)31)))|([0-9]{4}(-|\/)(?:0?[1-9]|1[0-2])(-|\/)(?:0?[1-9]|1\\d|2[0-8]))|(((?:(\\d\\d(?:0[48]|[2468][048]|[13579][26]))|(?:0[48]00|[2468][048]00|[13579][26]00))(-|\/)0?2(-|\/)29))))$"); return regex.test(this); } String.prototype.IsMobile = function () { []\d{}$/; return reg.test(this); } String.prototype.IsTelePhone = function () { \d{,})-)?(\d{,})(-(\d{,}))?$/; return reg.test(this); } String.prototype.IsEmail = function () { ,}){,})$/; return reg.test(this); } String.prototype.ToNumber = function () { : parseInt(this); } String.prototype.ToFloat = function () { : parseFloat(this); } String.prototype.ToDate = function () { var newDate = this.ToDateTime(); ); } getDate = function (strDate) { var date = eval('new Date(' + strDate.replace(/\d+(?=-[^-]+$)/, function (a) { ) - ; }).match(/\d+/g) + ')'); return date; } String.prototype.ToDateTime = function () { var ars = new Array(); ) { ars = ].split('/'); } else { ars = ].split('-') } ], ars[], ars[]); return newDate; } String.prototype.LRAllTrim = function () { return this.replace(/\s/g, ""); } // 日期处理所需的公用函数 function appendZero(n) { )); } /* //取得指定日期的年月日时分秒 //参数:dateValue 是格式形如:2007/04/05 function TimeCom(dateValue) { var newCom = new Date(dateValue); this.year = newCom.getFullYear(); this.month = newCom.getMonth() + 1; this.day = newCom.getDate(); this.hour = newCom.getHours(); this.minute = newCom.getMinutes(); this.second = newCom.getSeconds(); this.msecond = newCom.getMilliseconds(); this.week = newCom.getDay(); } */ // 日期格式化(0:2000年10月20日 1:2000-10-20 2:2000-10-20 30:24:00) Date.prototype.MyFormat = function (formattype) { var day = this; var dateString = ""; var thisyear = day.FormatYear(); ); var thisday = appendZero(day.getDate()); var thishour = appendZero(day.getHours()); var thismin = appendZero(day.getMinutes()); var thissec = appendZero(day.getSeconds()); switch (formattype) { : dateString = thisyear + "年" + thismonth + "月" + thisday + "日"; break; : dateString = thisyear + "-" + thismonth + "-" + thisday; break; : dateString = thisyear + "-" + thismonth + "-" + thisday + " " + appendZero(thishour) + ":" + appendZero(thismin) + ":" + appendZero(thissec); break; default: dateString = thisyear + "-" + thismonth + "-" + thisday; } return dateString; } // 日期格式化(0:2000年10月20日 1:2000-10-20 2:2000-10-20 30:24:00) Date.prototype.Format = function (formattype) { var day = this; var dateString = ""; var thisyear = day.FormatYear(); var thismonth = appendZero(day.getMonth()); var thisday = appendZero(day.getDate()); var thishour = appendZero(day.getHours()); var thismin = appendZero(day.getMinutes()); var thissec = appendZero(day.getSeconds()); switch (formattype) { : dateString = thisyear + "年" + thismonth + "月" + thisday + "日"; if (dateString == "2900年01月01日") { dateString = "永久有效"; } if (dateString == "1900年01月01日") { dateString = "未设置"; } break; : ") { thismonth = "; thisyear = accSub(thisyear, ); } dateString = thisyear + "-" + thismonth + "-" + thisday; if (dateString == "2900-01-01") { dateString = "永久有效"; } if (dateString == "1900-01-01") { dateString = "未设置"; } break; : dateString = thisyear + "-" + thismonth + "-" + thisday + " " + appendZero(thishour) + ":" + appendZero(thismin) + ":" + appendZero(thissec); if (dateString == "2900-01-01 00:00:00") { dateString = "永久有效"; } if (dateString == "1900-01-01 00:00:00") { dateString = "未设置"; } break; default: dateString = thisyear + "-" + thismonth + "-" + thisday; if (dateString == "2900-01-01") { dateString = "永久有效"; } if (dateString == "1900-01-01") { dateString = "未设置"; } } return dateString; } Date.prototype.FormatYear = function () { var theYear = this.getFullYear(); ); ) { tmpYear += ; ) { tmpYear += ; } } if (tmpYear < this.MinYear) { tmpYear = this.MinYear; } if (tmpYear > this.MaxYear) { tmpYear = this.MaxYear; } return (tmpYear); } // 在当前日期基础上增加指定的值 //参数:interval : y或year-表示取得相差的年份 n或month-表示相差的月份 d或day表示相差的天数 h或hour-表示相差的小时 m或minute-表示相差的分钟 s或second-表示相差的秒数 ms或msecond-表示相差的毫秒数 w或week-表示相差的周数 // num是偏移值,-表示向前推,+向后推 // dateValue 指定的日期 // formattype是返回的时间类型 //返回:返回时间串 Date.prototype.Add = function (interval, num) { var newCom = new TimeCom(this); switch (String(interval).toLowerCase()) { case "y": case "year": newCom.year += num; break; case "n": case "month": newCom.month += num; break; case "d": case "day": newCom.day += num; break; case "h": case "hour": newCom.hour += num; break; case "m": case "minute": newCom.minute += num; break; case "s": case "second": newCom.second += num; break; case "ms": case "msecond": newCom.msecond += num; break; ; break; default: return ("invalid"); } var now = newCom.year + "/" + newCom.month + "/" + newCom.day + " " + newCom.hour + ":" + newCom.minute + ":" + newCom.second; return new Date(now); } // 指定小数位数的四舍五入 Number.prototype.Round = function (v) { , v); return Math.round(this * vv) / vv; } // 检测文本框输入只能是正数Float类型 function isFloatPositive(jQuerySelector) { -]*[-][-]*$/; //^[1-9]\d*\.\d*|0\.\d*[1-9]\d*$正浮点数(8位小数)^\d+(\.\d+)?$ //确保用户输入的是正实数 if (isNaN($(jQuerySelector).val())) { $(jQuerySelector).val(''); return false; } if (!numFloatPositive.test($(jQuerySelector).val()) && $(jQuerySelector).val() != '') { document.execCommand('undo'); //确保用户输入的是正实数 return false; } return true; } //转换Json时间格式,如:/Date(1462269529000)/ function timeStamp2String(time) { var data = time; )); var year = datetime.getFullYear(); < ? ) : datetime.getMonth() + ; ? " + datetime.getDate() : datetime.getDate(); ? " + datetime.getHours() : datetime.getHours(); ? " + datetime.getMinutes() : datetime.getMinutes(); ? " + datetime.getSeconds() : datetime.getSeconds(); return year + "-" + month + "-" + date + " " + hour + ":" + minute + ":" + second; }