<commit_before># CreditCardValidations

Gem adds validator  to check whether or not a given number actually falls within the ranges of possible numbers prior to performing such verification, and, as such, CreditCardValidations simply verifies that the credit card number provided is well-formed.
This is a port of Zend Framework `Zend\Validator\CreditCard` .

## Build status
[![Build Status](https://travis-ci.org/Fivell/credit_card_validations.png)](https://travis-ci.org/Fivell/credit_card_validations)


## Installation

Add this line to your application's Gemfile:

    gem 'credit_card_validations'

And then execute:

    $ bundle

Or install it yourself as:

    $ gem install credit_card_validations

## Usage


The following issuing institutes are accepted:
    
    name             | key
    -----------------------
    American Express | :amex
    China UnionPay   | :unionpay
    Diners Club      | :diners
    Dinner Club US   | :diners_us
    Discover         | :discover
    JCB              | :jcb
    Maestro          | :maestro
    MasterCard       | :mastercard
    Solo             | :solo
    Visa             | :visa


Examples 

    number = "41111111111111111"
    CreditCardValidations::Detector.new(number).brand #:visa
    CreditCardValidations::Detector.new(number).visa? #true
    CreditCardValidations::Detector.new(number).valid?(:mastercard,:maestro) #false
    CreditCardValidations::Detector.new(number).valid?(:visa, :mastercard) #true

Also You can add your own rules to detect other credit card brands/types
passing name,length(integer/array of integers) and prefix(string/array of strings)
Example

    CreditCardValidations::Detector.add_rule(:voyager, 15, '86')
    voyager_test_card_number = '869926275400212'
    CreditCardValidations::Detector.new(voyager_test_card_number).brand #:voyager
    CreditCardValidations::Detector.new(voyager_test_card_number).voyager? #true
 


AvtiveModel support
	
only for certain brads	
	
	class CreditCardModel
  		attr_accessor :number
  		include ActiveModel::Validations
  		validates :number, presence: true, credit_card_number: {brands: [:amex, :maestro]}
	end
	
for all known brands<commit_msg>readme updated<commit_after># CreditCardValidations

Gem adds validator  to check whether or not a given number actually falls within the ranges of possible numbers prior to performing such verification, and, as such, CreditCardValidations simply verifies that the credit card number provided is well-formed.
This is a port of Zend Framework `Zend\Validator\CreditCard` .

## Build status
[![Build Status](https://travis-ci.org/Fivell/credit_card_validations.png)](https://travis-ci.org/Fivell/credit_card_validations)


## Installation

Add this line to your application's Gemfile:

    gem 'credit_card_validations'

And then execute:

    $ bundle

Or install it yourself as:

    $ gem install credit_card_validations

## Usage


The following issuing institutes are accepted:
    
    name             | key
    -----------------------
    American Express | :amex
    China UnionPay   | :unionpay
    Diners Club      | :diners
    Dinner Club US   | :diners_us
    Discover         | :discover
    JCB              | :jcb
    Maestro          | :maestro
    MasterCard       | :mastercard
    Solo             | :solo
    Visa             | :visa

Examples using string monkey patch

    require 'credit_card_validations/string'
    '5274 5763 9425 9961'.credit_card_brand
    '5274 5763 9425 9961'.valid_credit_card_brand?(:mastercard, :visa)  
    '5274 5763 9425 9961'.valid_credit_card_brand?(:amex)  


Examples using CreditCardValidations::Detector class

    number = "41111111111111111"
    CreditCardValidations::Detector.new(number).brand #:visa
    CreditCardValidations::Detector.new(number).visa? #true
    CreditCardValidations::Detector.new(number).valid?(:mastercard,:maestro) #false
    CreditCardValidations::Detector.new(number).valid?(:visa, :mastercard) #true

Also You can add your own rules to detect other credit card brands/types
passing name,length(integer/array of integers) and prefix(string/array of strings)
Example

    CreditCardValidations::Detector.add_rule(:voyager, 15, '86')
    voyager_test_card_number = '869926275400212'
    CreditCardValidations::Detector.new(voyager_test_card_number).brand #:voyager
    CreditCardValidations::Detector.new(voyager_test_card_number).voyager? #true
 


AvtiveModel support
	
only for certain brads	
	
	class CreditCardModel
  		attr_accessor :number
  		include ActiveModel::Validations
  		validates :number, presence: true, credit_card_number: {brands: [:amex, :maestro]}
	end
	
for all known brands
{'fraction_non_alphanumeric': 0.08878404460647651, 'fraction_numerical': 0.02573450568303667, 'mean_word_length': 3.626984126984127, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2415043', 'n_tokens_mistral': 1530, 'n_tokens_neox': 1394, 'n_words': 375}