Reputation: 20538
I am developing an Rails 4.1.4 web app and I need to validate that the users input is correct. The input is time in this format 12:00 (HH:MM). I just need to check that there are first 2 integers before the : and two integers after. How can I do this in a validation? I rather not use a gem for this simple task. I think it could be done with a regex?
Thanks!
Upvotes: 0
Views: 494
Reputation: 124419
You want validates_format_of:
validates_format_of :time, with: /\A\d{2}:\d{2}\z/
Upvotes: 2