Rails

Check If A String Only Contains A Number In Ruby

Posted by Weston Ganger on March 21, 2016

I was importing string values and needed to check that it was a positive number

Heres a simple regex to check this. This example will only work for positive integers.


"123abc" !~ /\D/ # => false
"123" !~ /\D/ # => true


Related External Links:


Posted in Rails and Tagged with ruby rails 


Want me to help develop your next project or application?

Contact Us

Specializing in Ruby-on-Rails, Javascript, Multi-Platform Electron Desktop Apps and Hybrid Cordova Mobile Apps.

Recommended Posts