rahult/credit_card_validation

View on GitHub
README.mdown

Summary

Maintainability
Test Coverage
# Credit Card Validation
[![Build Status](https://travis-ci.org/rahult/credit_card_validation.png?branch=master)](https://travis-ci.org/rahult/credit_card_validation) [![Code Climate](https://codeclimate.com/github/rahult/credit_card_validation.png)](https://codeclimate.com/github/rahult/credit_card_validation) [![Dependency Status](https://gemnasium.com/rahult/credit_card_validation.png)](https://gemnasium.com/rahult/credit_card_validation) [![Gem Version](https://badge.fury.io/rb/credit_card_validation.png)](http://badge.fury.io/rb/credit_card_validation)

This gem adds the capability of validating credit cards to ActiveRecord and ActiveModel (Rails 3+) and Ruby 1.9.2+.

### Installation

```ruby
# add this to your Gemfile
gem "credit_card_validation"
```

### and run

```ruby
bundle
```

### Usage

#### With ActiveRecord

```ruby
class Order < ActiveRecord::Base
  # standard validation
  validates :card_number, credit_card: true

  # with legacy syntax
  validates_credit_card :card_number

  # with custom message
  validates :card_number, credit_card: { message: "card is not valid?" }
end
```

#### With ActiveModel

```ruby
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.