Beer


#1

Hello, all

I have one string in my controller but i need to knwon how i verify if
it is numerical

Thanks…


#2

Regexp to the rescue:

if s =~ /[0-9]+/

I’m an integer, do something with me

end

And you can go from there, something like:

if s =~ /-?[0-9]+.[0-9]+/

I’m a postive/negative float

end

and further:

if s =~ /-?[0-9]+(.[0-9]+)/

I’m a positive/negative integer/float

end

And so on. Hope I got regexp right.

There might be pre-fab methods that do this, but I’m not sure off the
top of my head.

String numecal validate! wrote:

Hello, all

I have one string in my controller but i need to knwon how i verify if
it is numerical

Thanks…