user2993178 user2993178 - 1 year ago 82
Ruby Question

Verify formatting in a number

I have a table full of numbers and need to verify if each of the number has 0 decimals and has separators',' used for '000s .

Like: 123,456

How can i verify this?


Answer Source
s = '74,456,890'
if s =~ /^\d{1,3}(?:,\d{3}+)$/
   # String s has the required format
   # String s does not have the required format