Validation for non-negative integers and decimal values

Viewed 41861

My fields are: tax rate and tax amount in which I want to validate positive values.

I wrote this validation:

:format => { :with => /\A[+]?\d+\Z/}

But it is not taking numbers with a decimal point like 4.67. And it's throwing me an error. What type of validation will work on integers and floating point values? for example: 2, 57, 54.56 should pass but -2.56, -87 should fail.

3 Answers

you could use validates_numericality_of :amount, :greater_than => 0.0

Related