samedi 25 avril 2015

Validating minutes and seconds in Rails


I'm currently trying to validate a time based attribute called duration for one of my models. The attribute, would accept something along the lines of 01:30 as a valid value. The goal is to have a 4 digit time-code (minutes and seconds) with a colon in between the two. Both minutes and seconds limit in range 59 and cannot have 00:00 as a value. The regex I currently have doesn't seem to work:

validates :duration, presence: true, format: {with: /A([0-9]|0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]z/}


Aucun commentaire:

Enregistrer un commentaire