From: Logan Capaldo Date: 2006-08-30T06:12:51+09:00 Subject: Re: Testing a string's value is a positive integer On Aug 29, 2006, at 12:00 PM, James Deuchar wrote: > Hi, > > I'm trying to find an nice way of verifying that the value of a String > object (from the RoR params) contains a positive integer value. > Isn't this a job for validates_numericality_of ? validates_numericality_of :value, :only_integer => true Ok, it doesn't check for postiveness as far as I can tell but, thats just value > 0 given that you know its an integer. > Casting my string to_i and then testing that it is_a(Numeric) and > is > 0 > doesn't do the trick because the to_i method converts something like > '1.1' to a Fixnum of value 1 which would then pass the test when it > shouldn't... > > I feel certain I must be missing a trick here...am about to go down > the > path of regexp which feels...wrong? > > Any advice for a newcomer would be gratefully received! > > Thanks > > James > > > > -- > Posted via http://www.ruby-forum.com/. >