A simple credit card validator which will return the card type and validity.
Add this line to your application's Gemfile:
gem 'credit_card_validator', :git => "git@github.com:craigsheen/credit_card_validator.git"
And then execute:
$ bundle
Or install it yourself as:
$ gem install credit_card_validator
To check a credit card number simply input pass the number to the validate method:
$ CreditCardValidator.validate(n)
Examples:
$ CreditCardValidator.validate(4111111111111111)
$ => {:type=>"VISA", :number=>"4111111111111111", :valid=>"Valid"}
$
$ CreditCardValidator.validate(349999999999999)
$ => {:type=>"AMEX", :number=>"349999999999999", :valid=>"Invalid"}
$
$ CreditCardValidator.validate(12345)
$ => {:error=>"Unknown card type"}
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Added some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request