The title is pretty self explained, i need to get every character in a string, including numbers and special characters, and letters. What i'm trying to do is check if a text box has a letter or special character, 'cause i only want it to have numbers.
You can create an array of all the characters using the iterator returned by string.gmatch
when calling it with the .
class that represents any character.
local s = "hello world" local t = {} for c in s:gmatch(".") do table.insert(t, c) end
Alternatively you can use numerical for.
Though, this isn't the optimal way to solve your problem, unless you really want to do something with all the characters. You can use the string.match
function to grab the numerical part of the input. Then simply replace the current text with that numerical string.
textBox:GetPropertyChangedSignal("Text"):Connect(function() textBox.Text = textBox.Text:match("%d+") or "" -- if no chain of digits was found, replace the text with an empty string to avoid the API from throwing an error when attempting to apply "nil" to a property that expects a string end