Sanitize HTML string - Node.js String

Node.js examples for String:HTML String

Description

Sanitize HTML string

Demo Code


String.prototype.sanitize = function() {
  return this//w  w  w .  ja va 2  s . c  o  m
    .replace(/&/g, '&')
    .replace(/</g, '&lt;')
    .replace(/>/g, '&gt;')
    .replace(/"/g, '&quot;')
    .replace(/'/g, '&#39;')
}

Related Tutorials