Skip to content
Advertisement

Check if the string contains an entire word from an array of words (jquery, javascript)

I’m working on importing a word filter into a text input and I want to check if there is a match between a entire bad word that is in a array of words and a word that is inside a string, I will give an example of this…

List of bad words:

JavaScript

String with the value of text input:

JavaScript

Lets say I have this word in my string (In this example I expect a false answer):

JavaScript

Lets say I have this word in my string (In this example I expect a true answer):

JavaScript

Advertisement

Answer

After a slight correction to the code,

This is the code that solved this problem for me..Thx to ritaj

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement