A memo on regular expressions to check time format in Ruby.
When using it as a validator in Rails, it looks like this:
# Check if time format is correct
def validate_format_for_time
return if time.blank?
unless time =~ /^([0-1][0-9]|[2][0-3]):[0-5][0-9]$/
errors.add(:time, "を正しい形式で入力してください。")
end
end
That’s all from the Gemba.