How disallow player type letters in TextBox? (Only numbers)

I’m want make TextBox, which will receive number for grid, and IDK how force player to type only numbers and dot (1, 2, 3, 4, 5, 6, 7, 8, 9, 0, .), and don’t allow any letters (A, H, f, l…). Can someone give me tips, so I will able to make it?

TextBox:GetPropertyChangedSignal("Text"):Connect(function()
    local without_letters = string.gsub(TextBox.Text, "[A-z]","")
    if without_letters == TextBox.Text then
        return
    end
    TextBox.Text = without_letters
end)

This would go in a localscript btw

2 Likes

this is rather easy to solve

You can use tonumber() to check whether the written is a number or a letter

Example:

if tonumber(TextBox) then -- will run only if it's a number
  -- your code here
end

I didn’t run the code so I’m not sure about it

1 Like

Looked it up and [A-z] is the identifier for letters both capital and lowercase

I have only 1 queestion left:
There’s exist string patterns, for letters work fine %a
But what I should do to detect EVERY symbol (%p) exept for .?

That would be done with gsub

TextBox:GetPropertyChangedSignal("Text"):Connect(function()
    TextBox.Text = string.split(string.gsub(TextBox.Text, "%D", "")," ")[1]
end)

That allows only numbers, everything else in the string would be deleted

I’m already found answer, even for thing when I need keep dot (.) - [^%d\.]+

Thanks mate. This is the best solution imo.

1 Like