ruby on rails - How can I check if a value is a number? -


i want check if returned value form text field number i.e.: 12 , 12.5 or 12.75. there simple way check this, if value pulled param?

just regexp it, it's trivial, , not worth thinking beyond that:

v =~ /\a[-+]?[0-9]*\.?[0-9]+\z/ 

(fixed per justin's comment)


Comments

Popular posts from this blog

ruby - When to use an ORM (Sequel, Datamapper, AR, etc.) vs. pure SQL for querying -

php - PHPDoc: @return void necessary? -

c++ - Convert big endian to little endian when reading from a binary file -