My goal is to mask inappropriate words with asterisks ***
. However, I've encountered a challenge when the offensive word is part of another word that shouldn't be replaced.
for(var i = 0; i < forbidden.length; i++) {
if(textBoxValue.search(forbidden[i]) > -1) {
textBoxValue = textBoxValue.replace(forbidden[i], '');
}
}
For instance, if the unacceptable word is "are", and it appears within another word like "aren't", I do not want it to display as "***n't". The replacement should only occur if the word stands alone.