ruby on rails - How to validate price in input? -
i have input (it's text input) users can set price. problem is, users can set price this:
9 9.99 9,99 $9.99
what's best way validate input? running app on heroku (= postgresql database), data type column decimal.
try below. matches examples.
validates :price, :presence => true, :format => { :with => /^(\$)?(\d+)(\.|,)?\d{0,2}?$/ }
Comments
Post a Comment