Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@juspay/simple-card-validator

Package Overview
Dependencies
Maintainers
11
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@juspay/simple-card-validator

Card validation helpers for card number, expiry and CVV.

  • 1.2.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
318
decreased by-24.29%
Maintainers
11
Weekly downloads
 
Created
Source

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
FieldDescriptionType
card_typeThe card issuer for the provided cardString
validAre the card details validBoolean
luhn_validIs the card number validBoolean
length_validIf the card number length is validBoolean
cvv_lengthIf the CVV/CAVV length is validArray [ Integer ]
gapsGaps for UI as printed in cardsArray [ Integer ]
supported_lengthsSupported lengths for the card typeArray [ Integer ]
max_lengthMaximum length for the card typeInteger

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.

Keywords

FAQs

Package last updated on 09 Jun 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc