Jump to content




Detect if input is number or name


  • You cannot reply to this topic
1 reply to this topic

#1 tfoote

  • New Members
  • 134 posts
  • LocationSalt Lake, UT

Posted 06 July 2012 - 10:31 PM

Can you detect if an input such as
x =  io.read()
is a number or a word

#2 MysticT

    Lua Wizard

  • Members
  • 1,597 posts

Posted 06 July 2012 - 10:33 PM

You can detect if it's a number or not like this:
local input = read() -- get the input, doesn't really matter how
if tonumber(input) ~= nil then
  -- the input is a number
else
  -- the input is a word
end






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users