From: sto.mar@... Date: 2013-07-30T19:55:50+09:00 Subject: Re: How to check an input IS an integer ? Am 30.07.2013 12:03, schrieb Captain Ishido: > Hi everyone ! > I have a little problem since a few days. I would like to check that my > user (I am writing a small program) had type an integer while I asked him. There are several possibilities, the one I like best in this case is using a Regex (Note that user input is always a String): 2.0.0p247 :005 > answer = '123' => "123" 2.0.0p247 :006 > /\A[0-9]+\z/ === answer => true 2.0.0p247 :007 > answer = '123abc' => "123abc" 2.0.0p247 :008 > /\A[0-9]+\z/ === answer => false Other possibilities can easily be found by searching the archives, e.g. using Integer(), (which involves rescuing exceptions, which I do not like for this use case too much). Regards, Marcus -- GitHub: https://github.com/stomar/ PGP: 0x6B3A101A