I’m attempting to make a TextBox that only allows numbers (“%D+”) and colons (“:”), but I don’t seem to understand how to join them together - as it only allows me to use numbers or colons - how would I make it work with colons and numbers? This is what I tried so far:
bgTime.EndTime:GetPropertyChangedSignal("Text"):Connect(function()
local chars = string.len(bgTime.EndTime.Text)
bgTime.EndTime.Text = bgTime.EndTime.Text:gsub("%D+", "") --this line
if chars >= 5 then
bgTime.EndTime.Text = bgTime.EndTime.Text:sub(1, 5)
end
end)
-- count
local _, count = string.gsub(str, "[%:?%d%:?]+", "")
--match
print(str:match("[%:?%d%:?]+"))
-- with this pattern, the only match returned will be a string containing sections that contain a colon either right before or after a number
use an anchor if you need to start matching from either side of the string.