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?

    local without_letters = string.gsub(TextBox.Text, "[A-z]","")
    if without_letters == TextBox.Text then
    TextBox.Text = without_letters

This would go in a localscript btw


this is rather easy to solve

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


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

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.Text = string.split(string.gsub(TextBox.Text, "%D", "")," ")[1]

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