I have the following check for specific characters which we allow in our usernames:
var regex = /^[a-zA-Z0-9-_]+$/;
return regex.test(p1);
Does anyone know how I can implement a check for profanity? At the moment we just create users with the profane usernames and it blocks the username from being used because it’s already in use, but that’s using up our user table, and it isn’t very intuitive for the user to see that it’s just “in use” when changing their username.
The user tries to set the username to a blocked word, but sees it’s already taken and the app doesn’t allow them to change it.
The user “Profanity” with the username “@profanity”
Rather than creating a user row for each name you don’t want, I think it would be better to create a comma delimited list of profane words and any variations. Then turn that list into an array using a Split Text column. Then you can check if the entered username is included in that list and/or the list is included in the username.
This is what seemed to work best for me! Now, once an user tries to change their name to anything profane, vulgar, homophobic, transphobic, racist, sexist or other inappropriate things, my app will error out and won’t let the user change their username.
This is the prompt I used:
Does this username contain any vulgarity or profanity, or does it have any homophobic, transphobic, racist, sexist or other innapropriate connotations? Things like “I’m gay” or “lesbian lover” shouldn’t count.