Validating number using Ruby Regex -
working on rails project requires me validate number (representing day of month) either 1 or 15. placed following validation @ top of model:
validates :deposit_date, presence: true, format: { with: /\a1(5)?\z/ }
the regex works intended when use irb or online testers, fails validation in rails app. number being passed string, don't think it's type issue.
update: thank of relevent answers quickly. able track down issue... data in db invalid, causing seperate save! call fail ;)
try removing capture of 5.
{ with: /\a15?\z/ }
Comments
Post a Comment