credit_card_number_validator 1.0.4

  • Readme
  • Changelog
  • Example
  • Installing
  • 85

credit_card_number_validator #

A dart package to check if card number is valid and also returns card type as well.

Installing #

  1. Add dependency to pubspec.yaml

    Get the current version from the 'Installing' tab

dependencies:
    credit_card_number_validator: *current-version*
  1. Import the package
import 'package:credit_card_number_validator/credit_card_number_validator.dart';

Usage #

A basic example

Map<String, dynamic> cardData = CreditCardValidator.getCard(cardNumberString);
String cardType = cardData[CreditCardValidator.cardType];
bool isValid = cardData[CreditCardValidator.isValidCard];
# Features
* Supported cards:
  * Visa
  * Mastercard
  * American Express
  * Discover
  * Diners Club
  * JCB


# Author
Preeth Prathapan - *Creator and repo owner* - [Github Profile](https://github.com/preethzcodez)

# License
This project is licensed under the MIT License - see the [LICENSE file](LICENSE) for more details

[1.0.4] - July 23, 2019

  • Fixed Issue With MasterCard & JCB

[1.0.3] - July 23, 2019

  • Updated README.md

[1.0.2] - July 23, 2019

  • Stable Build

[1.0.1] - July 23, 2019

  • Updated README.md

[1.0.0] - July 23, 2019

  • Added Documentation

[0.0.2] - July 22, 2019

  • Updated README.md

[0.0.1] - July 22, 2019

  • Initial release

example/main.dart

import 'package:credit_card_number_validator/credit_card_number_validator.dart';
import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyApp createState() => _MyApp();
}

class _MyApp extends State<MyApp> {
  /// Card Number Controller
  TextEditingController _cardNumberController = TextEditingController();

  // Declare Variables To Store Card Type and Validity
  String cardType;
  bool isValid = false;

  // Initial State
  @override
  void initState() {
    // TODO: implement initState
    super.initState();

    // Set A Sample Card Value - VISA Card
    _cardNumberController.text = "4111111111111111";
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        home: Scaffold(
      appBar: AppBar(
        title: Text('Credit Card Validator Demo'),
      ),
      body: Center(
        child: Container(
            child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text(
              'ENTER CARD NUMBER',
              style: TextStyle(fontSize: 14.0, fontWeight: FontWeight.w800),
            ),
            Padding(
              padding: EdgeInsets.all(16.0),
              child: TextFormField(
                  keyboardType: TextInputType.number,
                  controller: _cardNumberController,
                  decoration: InputDecoration(
                      hintText: 'Card Number',
                      hintStyle: TextStyle(color: Color(0xFFCCCCCC)),
                      contentPadding: new EdgeInsets.symmetric(
                          vertical: 14.0, horizontal: 7.0),
                      focusedBorder: const OutlineInputBorder(
                        borderSide:
                            const BorderSide(color: Colors.grey, width: 0.0),
                      ),
                      enabledBorder: const OutlineInputBorder(
                        borderSide:
                            const BorderSide(color: Colors.grey, width: 0.0),
                      ),
                      border: const OutlineInputBorder(
                        borderSide:
                            const BorderSide(color: Colors.grey, width: 0.0),
                      ))),
            ),
            Container(
              height: 55,
              child: RaisedButton(
                color: Colors.blue,
                shape: RoundedRectangleBorder(
                    borderRadius: BorderRadius.all(Radius.circular(5))),
                child: Text('Get Card Data',
                    style: TextStyle(color: Colors.white, fontSize: 18.0)),
                onPressed: () {
                  // Get Card Type and Validity Data As Map - @param Card Number
                  Map<String, dynamic> cardData =
                      CreditCardValidator.getCard(_cardNumberController.text);
                  setState(() {
                    // Set Card Type and Validity
                    cardType = cardData[CreditCardValidator.cardType];
                    isValid = cardData[CreditCardValidator.isValidCard];
                  });
                },
              ),
            ),
            Padding(
              padding: EdgeInsets.all(20),
              child: cardType != null
                  // Display Card Type and Validity
                  ? Text('Card Type : $cardType \nCard Number Valid: $isValid',
                      style: TextStyle(
                          color: isValid ? Colors.green : Colors.red,
                          fontSize: 14.0,
                          fontWeight: FontWeight.w800))
                  : Text(' \n '),
            )
          ],
        )),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    ));
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  credit_card_number_validator: ^1.0.4

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:credit_card_number_validator/credit_card_number_validator.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
70
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
85
Learn more about scoring.

We analyzed this package on Oct 21, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.5.1
  • pana: 0.12.21
  • Flutter: 1.9.1+hotfix.4

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.7
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test