How do I detect if a string has only numbers, and no letters or words at all? From what I know, it’s possible.
Thanks.
How do I detect if a string has only numbers, and no letters or words at all? From what I know, it’s possible.
Thanks.
You can do this
if tonumber(string) then
-- string only has numbers
end
Can the string include plus or minus sign, the decimal marker (.
), hexadecimal using 0x
prefix, "inf"
, "infinity"
, "nan"
, or "nan(id)"
?
If so then the above reply would work.
If not and you’re actually looking for to check if the string has only numerical digits (0-9) and nothing else then you could try pattern matching (using string.match
) and then use the pattern ^%d+$
if empty strings are not accepted or ^%d*$
if so.
Yeah, that works very well, thanks
Yes, that can also be done, I am just new to LuaU, and I am still unsure on how to use the string
library.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.