How I can check number?

How I can to check float value, with regular expression. Also need check
a integer with float values.

···

--
Posted via http://www.ruby-forum.com/.

How I can simplify it:
params[:value] =~ /^\d+$|^-\d+$|^\d+\.\d+$|^-\d+\.\d+$/

···

--
Posted via http://www.ruby-forum.com/.

How I can to check float value, with regular expression. Also need check
a integer with float values.

The easiest check is to use Float and Integer:

Float("foo") rescue false

=> false

Float("1") rescue false

=> 1.0

Integer("10") rescue false

=> 10

Integer("10.4") rescue false

=> false

Kind regards

robert

···

2006/6/1, Ilyas <iiskakov@gmail.com>:

--
Have a look: Robert K. | Flickr

Ilyas wrote:

How I can simplify it:
params[:value] =~ /^\d+$|^-\d+$|^\d+\.\d+$|^-\d+\.\d+$/

/^ [-+]? \d+ (\. \d+)? $/x

Cheers,
Dave