user2993178 user2993178 - 3 months ago 9
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?

Thanks

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