Changing BackgroundColor3 to red when text isn't a number

Hey developers!

I’ve been trying to change the BackgroundColor3 to Color3.fromRGB(200, 0, 0) when the string isn’t a (string that can be converted into a) number. I’ve looked around on the DevForum, but couldn’t find any solutions.
Any help would be appreciated!

--Variables--
local list = script.Parent

--Script--
list.BubbleDuration.UserInput.Changed:Connect(function()
	if tonumber(list.BubbleDuration.UserInput.Text) or list.BubbleDuration.UserInput.Text == "" then
		list.BubbleDuration.UserInput.BackgroundColor3 = Color3.fromRGB(100, 100, 100)
		print("Success.")
	else
		list.BubbleDuration.UserInput.BackgroundColor3 = Color3.fromRGB(200, 0, 0)
		print("Error.")
	end
end)

Have a nice day, iamajust

You can also use string patterns to detect digits. I assume your numbers are always integers, so this can work pretty well:

if string.match(text, '^%d$') then --or you can do %d%d for double digits, or %d+ for as many digits as you want

end

Basically, %d gets any digits from 0-9. You can do %d+ to make sure it captures all the digits, but if you have a set number of digits, then you can do %d for as many digits. The ^ is an anchor that makes sure the pattern occurs at the beginning and $ makes sure it occurs at the end, so when you combine both, it makes sure the entire string is numerical.

Thanks for your amazing explanation and help! I will try this in a minute.

Is there any way I can check if the number is between 0 and 1? (Just asking since it doesn’t actually convert the string to a number.)