Check If A String Only Contains A Number In Ruby

Posted by Weston Ganger

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:

Article Topic:Software Development - Rails

Date:March 21, 2016

Recommended Posts

Contact

604-309-8713
info@solidfoundationwebdev.com

Send Me A Message

I would love to get in touch and talk about your next project. Feel free to send a message and I will get back to you shortly.

Get Connected