I am really new to ruby and want know if it's possible to check if a string contains only positive numbers using regex or some other function?
str = "123abcd" #return false because it contains alphabets
str = "153" #return true because of all numbers
0
by itself expresses a non-positive number. The0
in10
is part of a positive number. You cannot say whether0
as a digit is positive or not. Similarly,1
alone is a positive number.1
in-1
is part of a negative number.