Javascript String escape()

Description

Javascript String escape()


String.prototype.escape = function()
{
  return this.replace(/([ #;&,.+*~\':"!^$[\]()=>|\/])/g,'\\$1')
}

Javascript String escape()

String.prototype.escape = function() {
  return this.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
};

Javascript String escape()

// add escape for string
String.prototype.escape = function () {
    var entityMap = {
        "&": "&",
        "<": "&lt;",
        ">": "&gt;",
        '"': '&quot;',
        "'": '&#39;'
    };/*from   w w w .  j a  v a  2 s  .  c om*/

    return this.replace(/[&<>"']/g, function (s) {
        return entityMap[s];
    });
};

Javascript String escape()

var ENCODE_HTML_CHARACTERS = {
    '&': 'amp',
    '\'': '#039',
    '"': 'quot',
    '<': 'lt',
    '>': 'gt'
};

String.prototype.escape = function() {
    return this.replace(/(&|'|"|<|>)/g, function(m, k) {
        return ('&' + ENCODE_HTML_CHARACTERS[k] + ';') || k;
    });//  ww  w  .ja  v a 2s .  c  o m
};

Javascript String escape()

// Escape html characters.
String.prototype.escape = function() {
    var tagsToReplace = {
        '&': '&amp;',
        '<': '&lt;',
        '>': '&gt;'
    };// ww  w .ja  v a2s  . co  m
    return this.replace(/[&<>]/g, function(tag) {
        return tagsToReplace[tag] || tag;
    });
};

Javascript String escape()

String.prototype.escape = function() {
  var escape = document.createElement('textarea');
  escape.textContent = this;/*ww w .  j a v a 2 s .com*/
  return escape.innerHTML;
}

Javascript String escape()

String.prototype.escape = function() {
 return this/* ww w .  j  a  v a2  s . c  o  m*/
  .replace(/&(?!\w+;)/g, '&amp;')
  .replace(/</g, '&lt;')
  .replace(/>/g, '&gt;')
  .replace(/"/g, '&quot;');
};



PreviousNext

Related