dudeks Posted October 10, 2011 Posted October 10, 2011 Hi. I need a function isNumeric() to check an writed to gui text. Anywho have this function? :>
LoveFist Posted October 10, 2011 Posted October 10, 2011 function isNumeric(text) return tonumber(text) end
karlis Posted October 10, 2011 Posted October 10, 2011 function isNumeric(text) return tonumber(text) end correction function isNumeric(text) return tonumber(text) and true or false end
dudeks Posted October 10, 2011 Author Posted October 10, 2011 If text is: "18a" > \main_s.lua:174: attempt to compare number with nil It's don't work. I test it some times ago.
arezu Posted October 10, 2011 Posted October 10, 2011 function isNumeric(value) if(value == tonumber(value))then return true else return false end
dudeks Posted October 10, 2011 Author Posted October 10, 2011 This same. main_s.lua:174: attempt to compare number with nil
arezu Posted October 10, 2011 Posted October 10, 2011 show how you are calling the function in your script
karlis Posted October 10, 2011 Posted October 10, 2011 function isNumeric(text) if type(text)~="string" and type(text)~="number" then return false end return tonumber(text) and true or false end
dudeks Posted October 10, 2011 Author Posted October 10, 2011 age = guiGetText(editage) if isNumeric(age) then .... end edit: function isNumeric(text) if type(text)~="string" and type(text)~="number" then return false end return tonumber(text) and true or false end is working. Thanks!
AGENT_STEELMEAT Posted October 11, 2011 Posted October 11, 2011 Weird, I had: function isNumeric(text) if type(text) ~= "string" then text = tostring(text) end return tonumber(text) and true or false end
karlis Posted October 11, 2011 Posted October 11, 2011 function isNumeric(text) if type(text) == "string" then text = tostring(text) end return text and true or false end 2mistakes.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now