Validation for non-negative integers and decimal values

前端 未结 3 1523
暗喜
暗喜 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 14:17

    Doesn't this work?

    validates :your_field, :numericality => { :greater_than_or_equal_to => 0 }
    

    (guess for taxes following rule will be more correct:)

    validates :your_field, :numericality => { :greater_than_or_equal_to => 0, :less_than_or_equal_to => 100 }
    

提交回复
热议问题