Remove HTML Tags From String To Prevent XSS Attacks

Category: Javascript | May 10, 2018
Author: anandnat
Views Total: 268
Official Page: Go to website
Last Update: May 10, 2018
License: MIT

Preview:

Remove HTML Tags From String To Prevent XSS Attacks

Description:

Makes use of a little bit of JavaScript and Regular Expression to remove HTML tags from strings your user typed.

How to use it:

Insert the main function into your document.

function RemoveHtmlTags(a) {
  return a.replace(/(<([^>]+)>)/ig, "");
}

Remove the HTML5 tags from a string.

var output= RemoveHtmlTags('string here');

Remove whitespace from both sides of the string:

output.trim()

Leave a Reply