Validation for non-negative integers and decimal values

前端 未结 3 1528
暗喜
暗喜 2021-02-01 13:44

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

I wrote this validation:

:format => { :w         


        
3条回答
  •  无人共我
    2021-02-01 13:57

    You could use:

    validates :tax_rate, inclusion: { in: 0..5 }
    

    It allows values like: 0, 2, 1.2, 3.2

    Hope it helps!

提交回复
热议问题