Created
December 11, 2016 05:30
-
-
Save mengqing/b31b3b365a0671c5e25a5dd47aa64027 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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