rude word checker


I'm creating a website where the user can invent their own screen name. I want to make sure they don't come up with one containing swear words. can you advise how i would create a dictionary (or something) of rude words and name sure the screen name does not contain them.

In a screen name, what characters should i allow and disallow. I know underscores are useful but what about other characters, should i disallow them for simplicity?

Who is Participating?
JeffvClaytonConnect With a Mentor Commented:
just type each word as you would in a word document leaviing a space between each word. save as MySwearwords.txt. You could do this in notepad.

Read the entire file in using a textstream object and use the instr funtion to check for the password/swearword in the textstream objecte e.g

dim pos as long

    pos =  InStr(strContents, MySwearWord, CompareMethod.Text)                ....see function below for strContents

     pos will be 0 if no match found, otherwise pos will equal the start position of MySwearWord (password)

   Ypu may also want to loop through all your words in the text file to check in reverse against the password in case they have used a combination of other characters ans a swear word.

it may be better tp put each swearword on a new line in consideration of the loop for checking back to see if any part of the password is a swear word.

Heres some quick code to get your text file in to a variable: nothing checked as its late where i am (UK) but i will tomorrow. Full path = say C:\MyTextFile.txt

Public Function GetFileContents(ByVal FullPath As String, _
       Optional ByRef ErrInfo As String = "") As String

        Dim strContents As String
        Dim objReader As StreamReader

            objReader = New StreamReader(FullPath)
            strContents = objReader.ReadToEnd()
            Return strContents
        Catch Ex As Exception
            ErrInfo = Ex.Message
        End Try
    End Function
ZeonFlashConnect With a Mentor Commented:
To address the second part of your question, you should avoid allowing users to use characters that SQL uses as keywords.  This includes single quotes ('), remarks (-- or /* or */), and the wildcard operator (%).  In fact, it's generally easiest to run the user's suggested name through a regex that only allows for A-Z and 0-9 (and, as you mentioned, underscores).
gangwischConnect With a Mentor Commented:
the best way to do this is to put your swear words into an arraylist
dim swearwords as new arraylist

function checkIfHasSwearWords(byval username as string,byval a as arraylist) as boolean
for each item as string in a
if instr(username,item)>0 then return true
return false 'false if it doesnt have swear words in it
end function

good luck
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

oh yeah another comment:
if instr(username,item)>0 then return true
if instr(username.tolower,item)>0 then return true

and change all your curse words in the arraylist to lowercase

sorry about that
You could just type all your swear words in to a text file and use instr() function to check if any word in the file matches the login
andiejeAuthor Commented:
Thanks for your replies

Jeff, how would i do that option. Would i have one swear word per line? Could you give me some example code? I hanvet done much file manipulation.

Hope this enough to get you going before tomorrow

andiejeAuthor Commented:
THANKS a lot
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.