Giter Site home page Giter Site logo

mimbol228 / credit_card_type_detector Goto Github PK

View Code? Open in Web Editor NEW

This project forked from cholojuanito/credit_card_type_detector

0.0 0.0 0.0 7.24 MB

A Dart package that detects credit card types based on their prefixes

License: MIT License

Shell 2.66% Objective-C 1.48% Java 0.73% Dart 95.14%

credit_card_type_detector's Introduction

credit_card_type_detector | Credit Card Type Detector

A Dart package that detects credit card types based on the current credit card number patterns

This package is inspired by Braintree's credit-card-type module

Gif of the example app

Installing

Add dependency to your pubspec.yaml

Get the current version in the Installing tab on pub.dartlang.org

dependencies:
    credit_card_type_detector: <current_version>

Usage

import 'package:credit_card_type_detector/credit_card_type_detector.dart';

String visaStr = '4647 7200 6779 1032';

var types = detectCCType(visaStr);

assert(types.contains(CreditCardType.visa()))

Check out the example app in the example directory or the 'Example' tab on pub.dartlang.org for a more complete example using the BLoC pattern

Features

  • No external dependencies
  • Supported card types:
    • Create your own card types!
    • Default card types:
      • Visa
      • Mastercard
      • American Express
      • Discover
      • Diners Club
      • JCB
      • Union Pay
      • Maestro
      • Mir
      • Elo
      • Hiper/Hipercard

Pattern Detection

Each card type has a corresponding list of patterns. See the cardNumPatterns map. Each pattern is an array of strings that represents a range of numbers or a single number. These numbers correspond to the Issuer Identification number (IIN) for the credit card company.

There are two types of patterns:

  1. Single number pattern. The pattern number is compared against the card number. Partial matches for card numbers that are shorter than the pattern will count as matches (this is helpful for reactive text boxes where the UI can be updated as the user is typing).

    I.e. given the pattern '123', then the card numbers '1', '12', '123', '1234' will all match, but '2', '13', and '124' will not match.

  2. Range of numbers. The card number is checked to be within the range of those numbers in the pattern. Again, partial matches are looked for.

    I.e. given the range ['100', '123'], then the card numbers '1', '10', '100', '12', '120', '123' will all match, but '2', '13', and '124' will not match.

Every card type and all of its corresponding patterns are looped over when the function detectCCType is called. Whitespace is ignored in the string passed in.

Related Repos

Author

Cholojuanito (Tanner Davis) - Creator and repo owner - Github Profile

Support

If you think this package is helpful, tell your friends, give it a star on GitHub, and a like on pub.dev

License

This project is licensed under the MIT License - see the LICENSE file for more details

credit_card_type_detector's People

Contributors

cholojuanito avatar mimbol22 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.