Credit Card Validation
This gem adds the capability of validating credit cards to ActiveRecord and ActiveModel (Rails 3+) and Ruby 1.9.2+.
Installation
# add this to your Gemfile
gem "credit_card_validation"
# and run
bundle
Usage
With ActiveRecord
class Order < ActiveRecord::Base
# standard validation
validates :card_number, credit_card: true
# with legacy syntax
validates_credit_card :card_number
end
With ActiveModel
class Order
include ActiveModel::Validations
attr_accessor :card_number
validates :card_number, credit_card: true
end
I18n
The default error message is not a valid credit card
.
You can pass the message: "my custom error"
option to your validation to define your own, custom message.
Authors
Rahul Trikha (http://twitter.com/rahult)
License
Copyright 2013 by Rahul Trikha (http://www.rahultrikha.com) and is released under the MIT license.