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

How to check what type of text user typed?

3 answers

function check(var)
	if tonumber(var) ~= "" and tonumber(var) ~= nil then
		return true
	end
end

check(23)

try this

1 comment

0

btw this will still return true if there is text and numbers in the text box

Try this:

local textbox = script.Parent.TextBox

textbox.Changed:Connect(function()
local text = tonumber(textbox.Text)
	if text ~= nil then
		print(text)
	end
end)

If the text has any letter added, the if-then statement will prevent whatever you're trying to do from being fired.

To not let them type non-digit characters, you can use the string pattern %D+. It matches 1 or more occurrences of non digit characters.

With that in mind...

textbox.Text = textbox.Text:gsub("%D+", "")

will look for non digit characters and replace them with empty string "".

textbox:GetPropertyChangedSignal("Text"):Connect(function()
    textbox.Text = textbox.Text:gsub("%D+", "")
end)

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