Skip to content

Instantly share code, notes, and snippets.

@mengqing
Created December 11, 2016 05:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mengqing/b31b3b365a0671c5e25a5dd47aa64027 to your computer and use it in GitHub Desktop.
Save mengqing/b31b3b365a0671c5e25a5dd47aa64027 to your computer and use it in GitHub Desktop.
class WorkingTwelveHourFormat < ActiveModel::EachValidator
def validate_each(record, attribute, value)
unless value =~ /\A(?>(?>1[0-2]|0[1-9]):[0-5][0-9] pm|(?>1[01]|0[0-9]):[0-5][0-9] am)\z/
record.errors[attribute] << (options[:message] || "is not a valid working twelve hour format")
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment