How I can check number?


#1

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


#2

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


#3

2006/6/1, Ilyas removed_email_address@domain.invalid:

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


#4

Ilyas wrote:

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

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

Cheers,
Dave