How to make a formatted textbox check script?

So let’s say I have a text box that you can type in, but after focus is lost, I want a check script to run and reformat/revert to the last string if the criteria is not met.

Criteria I’m looking for

  • In the format ###.###
  • Only numbers (with the decimal in the middle)
  • Stays within 117.000 and 137.995
  • Can only be incremented by (0.005) for the decimal
  • Incremented by any amount for the whole number

Script I have so far:

local active = script.Parent
active.FocusLost:Connect(function()

end)

*based on a radio panel in a plane

Would be enormously appreciated if I could get this done, so please help out with any tips, solutions, etc.

ok so after some string docs research, I came up with this script that works just fine

local t = script.Parent
local rev
rev = t.Text
t.FocusLost:Connect(function()
	if string.len(t.Text) == 7 then
		if string.find(t.Text,".",4,true) ~= nil then
			local tempstring = string.split(t.Text,".",4)
			local tempHz = tempstring[1]
			local tempMHz = tempstring[2]
			if tonumber(tempHz) and tonumber(tempMHz) ~= nil then
				if tonumber(tempHz) >= 117 and tonumber(tempHz) <= 135 and tonumber(tempMHz) >= 000 and tonumber(tempMHz) <= 995 then
					if string.find(tostring(tempMHz),"0",3) ~= nil or string.find(tostring(tempMHz),"0",5)  then
						rev = tostring(tempHz .. "."..tempMHz)
						t.Text = tostring(tempHz .. "."..tempMHz)
					else
						t.Text = rev
					end
				else
					t.Text = rev
				end
			else
				t.Text = rev
			end
		else
			t.Text = rev
		end
	else
		t.Text = rev
	end
end)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.