Jump to content

Check if string contains value from table


UnchiuDawg

Recommended Posts

I'm trying to make my login panel not allow usernames that contain specific words to register.

I want to use a table since there are many words that I want to be restricted (like swear words), but I don't know how I could do this.

restrictedusernamewords = {"badword1", "badword2", "badword3"}

for k,v in ipairs(restrictedusernamewords) do
	if string.match(usernameregister, v) then
		outputChatBox ( "Please don't include vulgar words in your username!", client )
	else 
		register the account

Right now if the username doesn't contain all the words in the table, it will output the chat message and still register the account.

I searched and couldn't find anybody using string.match or string.find with a table like this, am I trying to do this the wrong way?

Edited by UnchiuDawg
Link to comment
local foundRestricted = false

for k,v in ipairs(restrictedusernamewords) do
	if string.match(usernameregister, v) then
		outputChatBox ( "Please don't include vulgar words in your username!", client )
		foundRestricted = true
		break
	end
end
if not foundRestricted then
	-- Do register
end

 

  • Like 1
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...