Created
February 7, 2018 13:52
-
-
Save guillefd/818aa99eadd5b3ea0eef336a865863df to your computer and use it in GitHub Desktop.
Angular, sanitize string: remove tags and urls
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
import { Injectable } from '@angular/core'; | |
@Injectable() | |
export class SecurityService { | |
constructor() { } | |
sanitizeAllTags(text:string) { | |
return text.replace(/<[^>]*>/g, '*'); | |
} | |
sanitizeAllUrl(text:string) { | |
return text.replace(/(?:https?|ftp|mailto):\/\/[\n\S]+/g, '*LINK*'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment