DEV Community

Cover image for Validate a Credit Card Number with Functional JavaScript

Validate a Credit Card Number with Functional JavaScript

Ben Lovy on November 03, 2019

Dolla Dolla Bill, Y'all Credit card companies are responsible for a high volume of highly sensitive global network traffic per minute wi...
Collapse
 
jlhernandez profile image
Info Comment hidden by post author - thread only accessible via permalink
Jose L. Hernández

Great article but a terrible topic for a "beginner-level" tutorial.

A small introduction to PCI compliance requirements would be great to stop beginners from thinking they can process credit card numbers as easy as this...

Collapse
 
deciduously profile image
Ben Lovy

The intended takeaways here are checksums and the functional-style implemention - definitely not intended as an introduction to financial processing.

Collapse
 
jlhernandez profile image
Jose L. Hernández

Sure, that's why I think it is a bad topic for a tutorial.
The programming style is cool, but it would be better if you implemented another algorithm, something that could be used in a real world app, or at least warn the readers they should never get credit card numbers in their app (unless they are building a bank..)

Thread Thread
 
deciduously profile image
Ben Lovy

Fair point!

Collapse
 
rohansawant profile image
Rohan Sawant

I always thought credit card numbers were mostly just sorcery.

Thanks for demystifying it!

Collapse
 
emily-flias profile image
Emily Flias
Collapse
 
alexfinch profile image
Info Comment hidden by post author - thread only accessible via permalink
Alex Finch • Edited

Hello Buddy,

I have found some related code that helps to validate Luhn checksum and it is easy to understand written in Javascript.

I attach code (Image Format) with this comment.

I would like to prefer one of the site that Generate and Validate Credit Card using Luhn Algorithm.

Collapse
 
vccgenerator profile image
Info Comment hidden by post author - thread only accessible via permalink
VCCGenerator • Edited

Hello Ben,

We've developed a credit card validator tool at VCCGenerator. But we need to validate the card details through javascript. Can you help with that?

Collapse
 
shortlonghair profile image
Short Hairstyle

The main advantage of the credit card generator is that it allows users to make use of the system even without the knowledge of the person using it. This way, a user will not be able to figure out whether the visa card generator is actually valid or not. Hence, people may end up spending more money on these fake generators than they actually have.

Collapse
 
poppybeck profile image
poppybeck • Edited

Hey Ben Lovy

Thanks for sharing information Validate a Credit Card or Debit Card Number with Functional JavaScript there are some sites on the internet which work with the Functional JavaScript one of the best examples is cardgenerators.org

Collapse
 
emnudge profile image
EmNudge

Protip:
You can reference the end of an array by using negative integers.
i.e.
Instead of .slice(0, len - 1) you can do .slice(0, -1)

Collapse
 
deciduously profile image
Ben Lovy

Ooh, thanks! Much nicer. JS is definitely not in my muscle memory yet.

Collapse
 
orighoprecious profile image
Origho Precious

Very nice article. kudos!

Collapse
 
bluebob profile image
bluebob

Great article - fascinating on a good few levels.
Thanks for sharing!

Collapse
 
portondr profile image
Info Comment hidden by post author - thread only accessible via permalink
portondr

Hi Ben How can i create a script code like Credit Card Generator With Address

Some comments have been hidden by the post's author - find out more