Forum: Ruby on Rails time textfield validation (hh:mm)

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Ee0293412faca21e4ebf3326ed9d5f8c?d=identicon&s=25 Kad Kerforn (kadoudal)
on 2009-06-02 15:00
(Received via mailing list)
I am trying to find the best way in validating a textfield
'start_time' in a form,
 based on the expected strftime format ("%I:%M%p")

if  a user  don't enter the correct format like " 01:45PM"    hh:mm in
12-hours (with PM/AM ) then should raise an error
I know it's possible to validate using gsub , but I wonder if there is
any possibility to raise an ArgumentError in parsing the value in a
Date/Time  function...

I tried

start_time = "89"
t = Time.parse( + "," + start_time)
but it doesn't raise an error...

4ab2692ba129cb296d4f2e90ba5241da?d=identicon&s=25 Sandip Ransing (san2821)
on 2009-06-02 17:05
(Received via mailing list)

You need not bother about date/time validations.
There is plugin called validates_date. just download & install it.
in your model,  add following line and you are done.

validates_date :field_name

Cheers !

On Tue, Jun 2, 2009 at 8:59 AM, Erwin <> wrote:

Ruby on Rails Developer
This topic is locked and can not be replied to.