String.prototype.ToCharArray = function(){return this.split("");}
String.prototype.Reverse 
= function(){return this.split("").reverse().join("");}
String.prototype.IsContains 
= function(str) { return (this.indexOf(str) > -1); } /* include or not ?*/
String.prototype.Format 
= function() { var args = arguments; return this.replace(/\{(\d+)\}/g, function(m, i, o, n) { return args[i]; }); }
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, "");} /*num only*/
String.prototype.GetEn 
= function(){return this.replace(/[^A-Za-z]/g, ""); } /* english charctar only */
String.prototype.GetCn 
= function(){return this.replace(/[^\u4e00-\u9fa5\uf900-\ufa2d]/g, ""); } /* chinese charctar only */
String.prototype.ByteLength 
= function(){return this.replace(/[^\x00-\xff]/g, "aa").length; } /* get Byte Length */
String.prototype.Left 
= function(n){return this.slice(0, n);}
String.prototype.Right 
= function(n){return this.slice(this.length - n);}
String.prototype.Insert 
= function(index, str) { return this.substring(0, index) + str + this.substr(index);}
String.prototype.Copy 
= function(){if(IE) window.clipboardData.setData("text"this.toString()); }/* ie only */
String.prototype.HtmlEncode 
= function(){var i,e ='&''&amp;''<''&lt;''>''&gt;''"''&quot;' },t = thisfor (i in e) t = t.replace(new RegExp(i, 'g'), e[i]);return t}
String.prototype.UrlEncode 
= function(){return encodeURIComponent(this); }
String.prototype.Unicode 
= function(){var tmpArr = []; for (var i = 0; i < this.length; i++) tmpArr.push("&#" + this.charCodeAt(i) + ";"); return tmpArr.join("");}
/*Validate*/
String.prototype.IsEmpty 
= function() { return 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.IsChinese 
= function(){return /^[\u0391-\uFFE5]+$/.test(this);}
String.prototype.IsQQ 
= function(){return /^[0-9]{5,9}$/.test(this);}
String.prototype.IsTel 
= function(){return /^(\(\d{3,4}\)|\d{3,4}-)?\d{7,8}$/.test(this);}
String.prototype.IsTelAll 
= function(){return /^(\(\d{3,4}\)|\d{3,4}-)?\d{7,8}$/.test(this|| /^\d{11}$/.test(this);} /* include cell phone */
String.prototype.IsNum 
= function() { return /^(\d+)$/.test(this); }
/*-- Array Class Extendtions --*/
Array.prototype.add 
= function(itAdd) { var _index = this.indexOf(itAdd); if (_index < 0) {this.push(itAdd);}};
Array.prototype.del 
= function(itDel) { var _index = this.indexOf(itDel); if (_index >= 0) { this.splice(_index, 1); }};
 posted on 2009-12-15 08:43  野人哥哥  阅读(274)  评论(0编辑  收藏  举报