Giter Site home page Giter Site logo

card-validator's Introduction

Card Validator

Generic helpers for card number, expiry and CVV validations

npm version

Usage:

Import the library and initialize card object.

Install from npm:

npm i @juspay/simple-card-validator --save

var cardValidator = require('simple-card-validator');

Or, you can simply use the file from dist/validator.js if you are not using node/npm.

var card = new cardValidator('4242-4242-4242-4242');

Getting card details

card.getCardDetails(); This would output, card brand and different validation outputs like below:

{ card_type: 'visa',
  valid: true,
  luhn_valid: true,
  length_valid: true,
  cvv_length: [ 3 ],
  gaps: [ 4, 8, 12 ],
  supported_lengths: [ 16 ],
  max_length: 16 }

Output format

Field Description Type
card_type The card issuer for the provided card String
valid Are the card details valid Boolean
luhn_valid Is the card number valid Boolean
length_valid If the card number length is valid Boolean
cvv_length If the CVV/CAVV length is valid Array [ Integer ]
gaps Gaps for UI as printed in cards Array [ Integer ]
supported_lengths Supported lengths for the card type Array [ Integer ]
max_length Maximum length for the card type Integer

Validations

To simply validate a card, call: card.validateCard(); The result will be a validity boolean.

For validating expiry date, card.validateExpiry('12/2018');

Additionally, the base date can be set for expiry validations. The base month and date can be provided by using, card.setBaseDate(month, year);

eg: card.setBaseDate('02', '2016');

For validating CVV, use: card.validateCvv(111); CVV will be validated based on the brand of the card.

Contribution

Read through the development guidelines.

License

MIT license. Copyright © 2018 - juspay.in.

card-validator's People

Contributors

amitrohan-juspay avatar avikantz avatar boazjohn avatar jamesgeorg avatar jxshco avatar nileshr avatar ramanathanrv avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

card-validator's Issues

Remove line to use in Browser

Hi, I've been using card-validator in a learning project and I've noticed that to use it in browser, with dist/validator.js is necessary to delete the last line in the file mentioned:

 module.exports = cardValidator;

Please check and update it.

Thanks.

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.