2016년 9월 6일 화요일

common.js

String.prototype.format = function (args) { var newStr = this; for (var key in args) { newStr = newStr.replace('{' + key + '}', args[key]); } return newStr; } String.prototype.formatAll = function (args) { var newStr = this; for (var key in args) { newStr = newStr.split("{" + key + "}").join(args[key]); } return newStr; } String.prototype.getLpad = function (spad, len) { var str = this; while (str.length < len) str = spad + str; return str; } String.prototype.getDateFormat = function () { var Week = ['일요일', '월요일', '화요일', '수요일', '목요일', '금요일', '토요일']; var year = this.substring(0, 4); var month = this.substring(4, 6); var day = this.substring(6, 8); var date = new Date(year, parseInt(month) - 1, day); return { date: "{YY}.{MM}.{DD}".format({ YY: year.substring(2, 4), MM: month, DD: day }), fullDate: "{YYYY}.{MM}.{DD}".format({ YYYY: year.substring(0, 4), MM: month, DD: day }), week: Week[date.getDay()], month: month + "월", day: day, orginDate: date } } String.prototype.isBlank = function () { var str = this.trim(); for (var i = 0; i < str.length; i++) { if ((str.charAt(i) != "\t") && (str.charAt(i) != "\n") && (str.charAt(i) != "\r")) { return false; } } return true; } String.prototype.isEmail = function () { return (/\w+([-+.]\w+)*@\w+([-.]\w+)*\.[a-zA-Z]{2,4}$/).test(this.trim()); } String.prototype.isDomain = function () { return (/\w+([-.]\w+)*\.[a-zA-Z]{2,4}$/).test(this.trim()); } String.prototype.isPhone = function () { var arg = arguments[0] ? arguments[0] : ""; return eval("(/(02|0[3-9]{1}[0-9]{1})" + arg + "[1-9]{1}[0-9]{2,3}" + arg + "[0-9]{4}$/).test(this)"); } String.prototype.isMobile = function () { var arg = arguments[0] ? arguments[0] : ""; return eval("(/01[016789]" + arg + "[1-9]{1}[0-9]{2,3}" + arg + "[0-9]{4}$/).test(this)"); } String.prototype.isBirth = function () { return (/(19|20)[0-9]{2}[01]{1}[0-9]{1}[0123]{1}[0-9]{1}$/).test(this.trim()); } String.prototype.isIncKor = function () { return (/[ㄱ-ㅎ|ㅏ-ㅣ|가-하]/).test(this) ? true : false; } String.prototype.isKor = function () { return (/^[가-힣]+$/).test(this) ? true : false; } String.prototype.isEngkor = function () { return (/^[가-힣]+$/).test(this) ? true : (/^[a-zA-Z]+$/).test(this) ? true : false; } String.prototype.num = function () { return (this.trim().replace(/[^0-9]/g, "")); } String.prototype.isNum = function () { return (/^[0-9]+$/).test(this) ? true : false; } String.prototype.isEng = function () { return (/^[a-zA-Z]+$/).test(this) ? true : false; } String.prototype.isEngNum = function () { return (/^[0-9a-zA-Z]+$/).test(this) ? true : false; } String.prototype.money = function () { var num = this.trim(); while ((/(-?[0-9]+)([0-9]{3})/).test(num)) { num = num.replace((/(-?[0-9]+)([0-9]{3})/), "$1,$2"); } return num; } //</String.prototype> String.prototype.decodeEntity = function () { return this.replace(/&amp;/gi, "&").replace(/&lt;/gi, "<").replace(/&gt;/gi, ">"); }; String.prototype.decodeCode = function () { return this.replace(/&#39;/g, "'") .replace(/&#40;/g, "(") .replace(/&#41;/g, ")") .replace(/&#34;/g, "'") .replace(/&#60;/g, "<") .replace(/&#62;/g, ">") .replace(/&#x0D;/gi, "\r"); }; String.prototype.stripHtml = function () { return $('<div/>').html(this).text(); }; Date.prototype.yyyymmdd = function () { var yyyy = this.getFullYear().toString(); var mm = (this.getMonth() + 1).toString(); var dd = this.getDate().toString(); return yyyy + (mm[1] ? mm : "0" + mm[0]) + (dd[1] ? dd : "0" + dd[0]); }; String.prototype.decodeEntity = function () { return this.replace(/&amp;/gi, "&").replace(/&lt;/gi, "<").replace(/&gt;/gi, ">"); }; String.prototype.decodeCode = function () { return this.replace(/&#39;/g, "'") .replace(/&#40;/g, "(") .replace(/&#41;/g, ")") .replace(/&#34;/g, "'") .replace(/&#60;/g, "<") .replace(/&#62;/g, ">") .replace(/&#x0D;/gi, "\r"); }; String.prototype.stripHtml = function () { return $('<div/>').html(this).text(); }; Date.prototype.yyyymmddDash = function () { var yyyy = this.getFullYear().toString(); var mm = (this.getMonth() + 1).toString(); var dd = this.getDate().toString(); return yyyy + '-' + (mm[1] ? mm : "0" + mm[0]) + '-' + (dd[1] ? dd : "0" + dd[0]); }; $.is_mobile = function () {     //if(TOUR_CLI_TP=='W') return false;     if (_agent.match(/android/) || _agent.match(/(iphone|ipod|ipad)/)) {         return typeof arguments[0] == 'undefined' ? true : (function (a, cs) {             return a.match((cs == 'android' ? /android/ : /(iphone|ipod|ipad)/)) ? true : false;         })(_agent, arguments[0]);     }     return false; };

댓글 없음:

댓글 쓰기