Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to detect if text is a number? [closed]

Asked by 6 years ago
Edited 6 years ago

This question already has an answer here:

How to tell if a Text is made up of numbers?

so i wanna detect if the text on a TextBox is a number. how could i do that?

Edit: Nvm, i had to use tonumber

Marked as Duplicate by cabbler and evaera

This question has been asked before, and already has an answer. If those answers do not fully address your question, then please ask a new question here.

Why was this question closed?

2 answers

Log in to vote
0
Answered by 6 years ago

do something like

if script.parent.Text = "1", "2"
0
Unless you have higher numbers than 1-2-3-4-5-6-7-8-9-0 that may be something else tightanfall 110 — 6y
0
yeah, with infinite numbers, good idea -_- SuperBeeperman 30 — 6y
Ad
Log in to vote
-1
Answered by 6 years ago
Edited 6 years ago
String="124124"
if tostring(tonumber(String)) == "" then 
    print'not Number' 
else
    print'Is number'
end

That is how to detect if it HAS numbers

EDIT:

That was a joke.

here is how to make the textbox only contain numbers

textBox.Changed:connect(function(p)
    if p=="text" then
        textBox.Text = tonumber(textBox.Text)
    end
end)
0
tysm SuperBeeperman 30 — 6y
0
np :) Internal_1 344 — 6y
0
This is wrong... nilVector 812 — 6y