How can I make a Javascript word filter? For example, I have a div
and within that div
I do not want to have certain words that are inside an array:
var badWords = ['teste', 'teste1', 'oteste2'];
How do I check if these words exist in the text and replace their content so that the first letter of that word appears, but the rest is marked with asterisks?
For example:
<div>Este texto tem as palavras: teste, teste1 e oteste2, e eu quero filtrar as palavras teste, oteste1 e teste2</div>
The content above would be replaced by something like this:
<div>Este texto tem as palavras: t****, t***** e o******, e eu quero filtrar as palavras t****, t***** e o******</div>
Remembering that I can not use jQuery, I would need to be in Javascript purely because it does not justify using the entire library just to do this ...