Skip to content

Instantly share code, notes, and snippets.

@intelekshual
Created April 7, 2011 21:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save intelekshual/908740 to your computer and use it in GitHub Desktop.
Save intelekshual/908740 to your computer and use it in GitHub Desktop.
credit card expiration date validator
class ExpirationDateValidator < ActiveModel::EachValidator
def validate_each(object, attribute, value)
expiration_date, today = value, Date.today
if today.year > expiration_date.year || today.month > expiration_date.month
object.errors[attribute] << (options[:message] || "is not valid")
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment