String character whitelist system

How would I go about checking a string for a list of whitelisted characters and then removing the ones that arent whitelisted.

  1. Basically im greating a group system where it lists my groups allies into teams, the problem is some of their groups have special characters in their name which roblox does NOT support. Meaning the teams are being created but not listed.

  2. Im not asking for you to code it for me im just asking how id go about doing so.

Here’s what I tried.

function OnPlayerAdded(player)
	print("You are on these factions:")
	for _,group in pairs(allies) do
		if player:IsInGroup(group.Id) then
			print(group.Name)
			
			local team = Instance.new('Team')
			team.Parent = game.Teams
			team.Name = group.Name
		end	
	end
end

It creates the teams correctly just once again those characters that aren’t supported by roblox cause teams to not be listed.

image

Have you ever heard of ASCII code?

print(string.byte("A")) --> It prints "65", which is A's special "ID"
print(string.char(65)) --> It prints "A" because 65 is A in ASCII code

I think that my hint might help you.
Edit: I’m actually not sure for some reason.
An another edit: Nvm, I was just somehow dumb.
The last edit: It was just me confusing myself.

I think what I might need to do is make a table of whitelisted characters and if its not valid then it replaces removes it, possibly by somehow separating the characters one by one and then figuring out which is not whitelisted?

Is this what you want?

local text = "Brick"
for i, character in pairs(text:split("")) do
print(character)
end

Yes that might help hold on ill message you in a bit when I come up with something.

I will go to sleep so expect me not being able to help for hours. Hopefully you can help yourself or someone else can help you.

so you can use this validator function to detect any special chars

local function validateTeamName(name :string) :boolean
    for start, stop in utf8.graphemes(name) do
    	if start-stop ~= 0 then
            return false
        end
    end
    return true
end

print("erty¢u", validateTeamName("erty¢u"))
print("Real Name", validateTeamName("Real Name"))

UTF8 documentation: utf8 | Roblox Creator Documentation
Internally rbx thinks ¢ is 2(or more) chars when you index the string using a position or look at the string’s length

1 Like

that almost works, now I just need to recombine the characters.

1 Like

Here you go:

local text, illegalCharacters = "aaaXbbbYcccZ", {"X", "Y", "Z"}
local splittedText = text:split("")
text = ""
for i, character in pairs(splittedText) do
if table.find(illegalCharacters, character) == nil then
text ..= character
end
end
print(text)
1 Like