No commit activity in last 3 years
No release in over 3 years
Ruby library to validate payment card numbers
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

 Project Readme

card_number_validator Gem Version Build Status Code Climate

CardNumberValidator provides methods to validate the most used card flags in the world. In addition, you can generate fake card numbers for development and tests purposes.

Installation

Add card_number_validator to Gemfile Gemfile:

gem 'card_number_validator'

Download and install by running:

bundle install

Usage

CardNumberValidator.flag(card_number)

Returns the flag name of the card or :unknown when the number is invalid.

See Example:

  CardNumberValidator.flag('378282246310005')  # :amex
  CardNumberValidator.flag('30569309025904')   # :diners
  CardNumberValidator.flag('6363683839698868') # :elo
  CardNumberValidator.flag('6062826289081176') # :hipercard
  CardNumberValidator.flag('4012888888881881') # :visa
  CardNumberValidator.flag('5223358786371817') # :mastercard
  CardNumberValidator.flag('1111111111111111') # :unknown

CardNumberValidator.valid?(card_number)

Checks if the given card number is valid or not.

See Example:

  CardNumberValidator.valid?('378282246310005')  # true
  CardNumberValidator.valid?('30569309025904')   # true
  CardNumberValidator.valid?('6363683839698868') # true
  CardNumberValidator.valid?('6062826289081176') # true
  CardNumberValidator.valid?('4012888888881881') # true
  CardNumberValidator.valid?('5223358786371817') # true
  CardNumberValidator.valid?('1111111111111111') # false

CardNumberValidator.generate(:flag_name)

Returns a fake card number for the given flag name.

See Example:

  CardNumberValidator.generate(:amex) # '378282246310005'

String#card_flag

Returns the card flag for the given card number

See Example:

  '378282246310005'.card_flag  # :amex
  '30569309025904'.card_flag   # :diners
  '6363683839698868'.card_flag # :elo
  '6062826289081176'.card_flag # :hipercard
  '4012888888881881'.card_flag # :visa
  '5223358786371817'.card_flag # :mastercard
  '1111111111111111'.card_flag # :unknown

Contributing

Card Validator is open source, and we are grateful for everyone who's contributed so far.

License

It is free software, and may be redistributed under the terms specified in the MIT-LICENSE file.

Feature Requests & Bugs

See http://github.com/pauloh-silva/card_number_validator/issues