Credit Card Validation in Node.js

Yesterday, I published a module named credit-card to npm. As the name somewhat implies, this module performs validation on credit card information. I’ve tried my best to make it flexible, with features like:

  • The ability to define customer card types. I see this feature being used to implement gift cards, etc.
  • The ability to define the schema of the input data. Basically, this just means that instead of calling a field expiryMonth, you can call it something like expires.month or expiration_month. The idea is to let the module work with different APIs.
  • The ability to validate all fields of a credit card in one shot, or validate individual fields via separate methods.
  • Support for Visa, Mastercard, American Express, Discover, Diner’s Club, and JCB cards.
  • Usage of the Luhn algorithm.

credit-card has only one dependency – hoek, a utility module from Walmart Labs. There is also a suite of tests provided that achieve 100% code coverage.

I hope someone out there finds it useful. If so, I’d love to hear about it!

Comments are closed.