Flutter Credit Card Number Validator

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

Description

Requirements

  • Flutter Basics
  • VS Code Program
  • Android Studio Program

Description

Flutter Credit Card Number Validator:

In this tutorial, we are going to learn how to validate a credit card and what is its card type, etc. We have different credit card types some of them are Visa, Mastercard, American Express, Discover, Dinner Club, and JCB, etc. So we are validating the different card types with their number and it’s card type means it validates the credit card and returns its type.

This example supports following cards:

Supported cards:

  • Visa
    Mastercard
    American Express
    Discover
    Diners Club
    JCB

Follow the below steps to Implement Flutter credit card Validator:

Add the dependency package:

adding the dependency package to pubspec.yaml file. use the below code to add the dependency package. After adding the dependency package run the get package method to import all the required files to the app.

dependencies:
credit_card_number_validator: ^1.0.4

Install the package:

You can install the package from the command line using the below code with Flutter as shown.

$ flutter pub get

Importing the Package:

After Adding the dependency package to the pubspec.yaml file , you can now import the package into the dart code by using the below code. without adding the dependency packge to the pubspec.yaml file if you import it will show package not found an error.

import ‘package:credit_card_number_validator/credit_card_number_validator.dart’;

Use the following example code into your dart file :

Map cardData = CreditCardValidator.getCard(cardNumberString);
String cardType = cardData[CreditCardValidator.cardType];
bool isValid = cardData[CreditCardValidator.isValidCard];

Who this course is for:

  • Geeks
  • Students
  • Any Person Using Flutter in Projects

Reviews

There are no reviews yet.

Be the first to review “Flutter Credit Card Number Validator”