Created
December 3, 2014 09:06
-
-
Save baniol/9e44027b41012af73921 to your computer and use it in GitHub Desktop.
sanitize html in javascript. http://stackoverflow.com/a/10772475
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String.prototype.sanitizeHTML=function (white,black) { | |
if (!white) white="b|i|p|br";//allowed tags | |
if (!black) black="script|object|embed";//complete remove tags | |
e=new RegExp("(<("+black+")[^>]*>.*</\\2>|(?!<[/]?("+white+")(\\s[^<]*>|[/]>|>))<[^<>]*>|(?!<[^<>\\s]+)\\s[^</>]+(?=[/>]))", "gi"); | |
return this.replace(e,""); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment