js - 이 형

7563 단어
/*
              
 */
Array.prototype.foreach = function(lpfun) {for (i = 0; i < this.length; i++){if(this[i]!='') {lpfun(this[i])}}}
Array.prototype.foreachindex = function(lpfun) {for (i = 0; i < this.length; i++){if(this[i]!='') {lpfun(i,this[i])}}}
Array.prototype.Add=function(value){this.push(value)}
Array.prototype.foreachdic=function(lpfun){dic=this;for(key in dic){lpfun(dic[key])}}
Array.prototype.del = function(n){if (n < 0)return this;else return this.slice(0, n).concat(this.slice(n + 1, this.length));}
String.prototype.foreach=function(strsplit,lpfun){data=this.split(strsplit);for(i=0;i=Fields.length)priindex=-1;
        var ret=[]
        for(i=0;i=0) {ret[record[Fields[priindex]]]=record}
            else ret[priindex]=record
        }
        return ret
    }
//      IP  
String.prototype.isIP = function() {
        var reSpaceCheck = /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/;
        if (reSpaceCheck.test(this)) {
            this.match(reSpaceCheck);
            if (RegExp.$1 <= 255 && RegExp.$1 >= 0 && RegExp.$2 <= 255 && RegExp.$2 >= 0 && RegExp.$3 <= 255 && RegExp.$3 >= 0 && RegExp.$4 <= 255 && RegExp.$4 >= 0) return true;
            else return false;
        } else return false;
    }
//         
String.prototype.isLongDate = function() {
        var r = this.replace(/(^\s*)|(\s*$)/g, "").match(/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2}) (\d{1,2}):(\d{1,2}):(\d{1,2})$/);
        if (r == null) return false;
        var d = new Date(r[1], r[3] - 1, r[4], r[5], r[6], r[7]);
        return (d.getFullYear() == r[1] && (d.getMonth() + 1) == r[3] && d.getDate() == r[4] && d.getHours() == r[5] && d.getMinutes() == r[6] && d.getSeconds() == r[7]);
    }
//         
String.prototype.isShortDate = function() {
        var r = this.replace(/(^\s*)|(\s*$)/g, "").match(/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/);
        if (r == null) return false;
        var d = new Date(r[1], r[3] - 1, r[4]);
        return (d.getFullYear() == r[1] && (d.getMonth() + 1) == r[3] && d.getDate() == r[4]);
    }
//        
String.prototype.isDate = function() {return this.isLongDate() || this.isShortDate();}
//     
String.prototype.isMobile = function() {return /^0{0,1}13[0-9]{9}$/.test(this);}
//     
String.prototype.isEmail = function() {return /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/.test(this);}
//       
String.prototype.toCharArray = function() {return this.split("");}
//  N        
String.prototype.repeat = function(num) {
    var tmpArr = [];
    for ( var i = 0; i < num; i++)
        tmpArr.push(this);
    return tmpArr.join("");
}
//   
String.prototype.reverse = function() {return this.split("").reverse().join("");}
//        
String.prototype.isNumeric = function() {
    var tmpFloat = parseFloat(this);
    if (isNaN(tmpFloat))
        return false;
    var tmpLen = this.length - tmpFloat.toString().length;
    return tmpFloat + "0".Repeat(tmpLen) == this;
}
//        
String.prototype.isInt = function() {if (this == "NaN")return false;return this == parseInt(this).toString();}
//             
String.prototype.resetBlank = function() {return this.replace(/s+/g, " ");}
//        
String.prototype.LTrim = function() {return this.replace(/^s+/g, "");}
//        
String.prototype.RTrim = function() {return this.replace(/s+$/g, "");}
//        
String.prototype.trim = function() {return this.replace(/(^s+)|(s+$)/g, "");}
//      
String.prototype.getNum = function() {return this.replace(/[^d]/g, "");}
//      
String.prototype.getEn = function() {return this.replace(/[^A-Za-z]/g, "");}
//      
String.prototype.getCn = function() {return this.replace(/[^u4e00-u9fa5uf900-ufa2d]/g, "");}
//        
String.prototype.getRealLength = function() {return this.replace(/[^x00-xff]/g, "--").length;}
//             
String.prototype.left = function(n) {return this.slice(0, n);}
//             
String.prototype.right = function(n) {return this.slice(this.length - n);}
// HTML   
String.prototype.HTMLEncode = function() {
    var re = this;
    var q1 = [ /x26/g, /x3C/g, /x3E/g, /x20/g ];
    var q2 = [ "&", "", " " ];
    for ( var i = 0; i < q1.length; i++)
        re = re.replace(q1[i], q2[i]);
    return re;
}
// Unicode   
String.prototype.ascW = function() {
    var strText = "";
    for ( var i = 0; i < this.length; i++)
        strText += "" + this.charCodeAt(i) + ";";
    return strText;
}
String.prototype.foreach=function(strsplit,lpfun){data=this.split(strsplit);for(i=0;i=Fields.length)priindex=-1;
        var ret=[]
        for(i=0;i=0) {ret[record[Fields[priindex]]]=record}
            else ret[priindex]=record
        }
        return ret
    }
//      IP  
String.prototype.isIP = function() {
        var reSpaceCheck = /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/;
        if (reSpaceCheck.test(this)) {
            this.match(reSpaceCheck);
            if (RegExp.$1 <= 255 && RegExp.$1 >= 0 && RegExp.$2 <= 255 && RegExp.$2 >= 0 && RegExp.$3 <= 255 && RegExp.$3 >= 0 && RegExp.$4 <= 255 && RegExp.$4 >= 0) return true;
            else return false;
        } else return false;
    }
    //         
String.prototype.isLongDate = function() {
        var r = this.replace(/(^\s*)|(\s*$)/g, "").match(/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2}) (\d{1,2}):(\d{1,2}):(\d{1,2})$/);
        if (r == null) return false;
        var d = new Date(r[1], r[3] - 1, r[4], r[5], r[6], r[7]);
        return (d.getFullYear() == r[1] && (d.getMonth() + 1) == r[3] && d.getDate() == r[4] && d.getHours() == r[5] && d.getMinutes() == r[6] && d.getSeconds() == r[7]);
    }
    //         
String.prototype.isShortDate = function() {
        var r = this.replace(/(^\s*)|(\s*$)/g, "").match(/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/);
        if (r == null) return false;
        var d = new Date(r[1], r[3] - 1, r[4]);
        return (d.getFullYear() == r[1] && (d.getMonth() + 1) == r[3] && d.getDate() == r[4]);
    }
    //        
String.prototype.isDate = function() {return this.isLongDate() || this.isShortDate();}
    //     
String.prototype.isMobile = function() {return /^0{0,1}13[0-9]{9}$/.test(this);}
    //     
String.prototype.isEmail = function() {return /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/.test(this);}

좋은 웹페이지 즐겨찾기