Pure Programmer
Blue Matrix


Cluster Map

Project: Credit Card Validator

The [[Luhn Algorithm]] is a simple checksum algorithm that is used to verify that credit card numbers are correctly entered. Using this algorithm we can easily catch most single digit errors and simple transpositions.

Write a function to verify that the last digit of a credit card is the one expected when computing a checksum digit using the Luhn Algorithm. The function should take a credit card number as a string of 16 digits (no spaces) and return true or false if the last digit matches the computed checksum. Test the program with your own credit card numbers or the samples below.

Output
$ perl CreditCardValidator.pl Good Test Cases 4321123456789019 is 1 5432123456789020 is 1 65432101234567896 is 1 Bad Test Cases 4321123456798019 is 4432123456789020 is 65431201234567896 is

Solution