Beer

Hello, all

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

Thanks…

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…

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs