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 


Need help on your next project or application?

I specialize in Ruby-on-Rails, AngularJS, Javascript, Bootstrap, and Hybrid Mobile Apps with Cordova & Ionic.

Contact Me

Recommended Posts