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

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -