Skip to content

Instantly share code, notes, and snippets.

@guillefd
Created February 7, 2018 13:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guillefd/818aa99eadd5b3ea0eef336a865863df to your computer and use it in GitHub Desktop.
Save guillefd/818aa99eadd5b3ea0eef336a865863df to your computer and use it in GitHub Desktop.
Angular, sanitize string: remove tags and urls
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