Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Best method to filter out textboxes to only contain specific characters?

Hi there,

So I'm making a Color3 input system but I don't want people inputting something that isn't a number value up to 3 characters long, of course I could have a filter checking if there is anything other than the numbers 0-9 and it's less than 4 characters, but I want it to be instantaneously checking and removing characters that are not in line with the filter I set up, this is probably simple but since I'm not experienced with many string related functions I don't know how I'd do it

I would give a code sample but I have little to no knowledge on most functions related to strings except a few basic ones.

1 answer

Well for the characters we can use a function called gsub and for the numbers, we can use the length. So here is how it would look like this is the line of code you would want to use to remove all alpha letters and punctuation and lets the program know if the color3 value passed is under 9 numbers long here is the code

if print(#(string.gsub("HiLol12!","[A-Za-z%p]",""))) < 9 then 
	-- Do you code
end

Breakdown: string.gsub("HiLol12!","[A-Za-z%p]","") --This removes all alpha letters (the one with ^[A-Za-z]), the %p removes punctioation

(the code) -- This one gets the length once we removed all unwanted characters

If you want more help with more technical aspects of lua you can always refer to https://www.lua.org/pil/1.html

4 comments

0

Sry forgot to remove the print statement

0

sry for the bold text idk why it is happening

0

I've figured out a method to determine the length but I'm not sure how I'd delete the characters so I've opened another question to figure that out

0

no use the string.gsub("HiLol12!","[A-Za-z%p]",""

This discussion is preserved as it was. New answers, comments, and votes are closed.