Google-sheets – Preventing certain words from appearing on a Google Sheets

google sheetsgoogle-apps-scriptregex

Let's say that I have a big Google spreadsheet that multiple users have access to, and I'm not able to control which users have access to it. I have a concern for trolls.

How would I prevent people from entering certain words, specifically slurs and curse words, something fancy with regex in the form?

Best Answer

Yes you can use regexmatch with the "custom formula" option on the data validation menu item.

Create a list of all the words you want to reject and join them with the | as your delimiter, which represents "or" in regex.

I recommend leaving them lower case and then within the formula we will also lowercase the text to make sure we catch both cases/scenarios, but for example I did the validation on all of column H:

=if(REGEXMATCH(LOWER(H:H),"then|text"),False,True)

The words I chose to reject were then and text - if you choose not to reject the input but just flag it it will look like the image below, alternatively you can choose "reject input" and that will literally reject any cell they try to enter that contains your offensive strings.

enter image description here

PS if you choose reject, it wont ever even get entered in like it does in the image - i just wasnt able to capture an event NOT occurring in a photograph lol