Logo

Programming-Idioms

History of Idiom 137 > diff from v14 to v15

Edit summary for version 15 by Nepta:
New Lua implementation by user [Nepta]

Version 14

2016-09-14, 20:42:12

Version 15

2016-11-06, 21:16:21

Idiom #137 Check if string contains only digits

Set boolean b to true if string s contains only characters in range '0'..'9', false otherwise.

Idiom #137 Check if string contains only digits

Set boolean b to true if string s contains only characters in range '0'..'9', false otherwise.

Code
b = tonumber(s) ~= nil
Comments bubble
you could use pattern too
Doc URL
http://www.lua.org/manual/5.3/manual.html#pdf-tonumber
Demo URL
http://codepad.org/mofwXd2y