Remove reserved characters from a text string.
How do you remove all reserved HTML characters from a string and replace them like the following:
- '&' (ampersand) becomes '&'.
- '"' (double quote) becomes '"'.
- ''' (single quote) becomes '''.
- '<' (less than) becomes '<'.
- '>' (greater than) becomes '>'.
If you want to do this you can make a JavaScript function like:
var cleanHtmlText = function (dirtyCode) {
return dirtyCode.replace(/&/g, "&")
.replace(/"/g, """)
.replace(/'/g, "'")
.replace(/</g, "<")
.replace(/>/g, ">");
};
You can see the instruction video at youtube by clicking on this text here. To see how it works: Play around!