Javascript String Method

String.prototype.trim = function() {
   return this.replace(/^\s+|\s+$/g,"");
}

String.prototype.htmlEntities = function () {
   return this.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;');
}

String.prototype.stripTags = function () {
   return this.replace(/<([^>]+)>/g,'');
}

String.prototype.esc = function () {
   return encodeURIComponent ? encodeURIComponent(this) : escape(this);
}

0 Comments

Post A Comment