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(Time.now.to_date.to_s + “,” + start_time)
but it doesn’t raise an error…
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.