How I can check number?

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

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

2006/6/1, Ilyas [email protected]:

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

Ilyas wrote:

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

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

Cheers,
Dave