'Check if username contains curse words

I have a user register system where users can change their username to something like "username123" except I would like to filter those usernames from hate and harassment what would be the best way to do this?

I was thinking of making a new table in phpmyadmin with specific words and compare those with the _post username in php, but maybe their is a better / faster way to do this? I do have a .txt file with the specific words.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source