A credit card is provided by various companies and banks to the consumer. Robertson Inc., a private local bank is working towards providing credit card services to its customer and is looking for the credit card validator tool. Can you help write such validator?

Challenge

Write a program validate an input credit card number.

Facts

  • A credit card length varies from the company that provides the card, generally, varies from 13 to 16 digit in length.
  • The following are the various type of credit cards in the market today:
  • Visa - starts with 4, with a length of 13 or 16 digits.
  • MasterCard - starts with 51 through 55, with a length of 16 digits.
  • American Express - starts with 34 or 37, with a length of 15 digits.
  • Discover- starts with 6011, with a  length 16 digits or start with 5,  with a length of 15 digits.
  • Diners Club - starts with 300 through 305, with a length of 14 digits.
  • JCB - starts with 2131 or 1800, with a length of 15 digits or starts with 35, with a length of 16 digits.

Validation Logic

  • Irrespective the type of credit (issuer) and the length of the credit card all Credit cards can be validated using a simple check digit process called the Luhn algorithm.

  • Example consider a fictitious credit card number. Starting from the right to left of digits, multiple every alternate digit by 2 as:
    4819 3046 4254 2286 <--- A fictitious, Credit card
    2121 2121 2121 2121 <--- Multiply each digit in the top number by the digit below it.
    If the result of this multiplication is a two-digit number, add the digits together.

  • In this example, the second-to-last column, when you multiply 8 by 2 results in 16.  Since the result is a two-digit number, add the numbers instead.

  • Add the results digits (1 and 6) together (1 + 6 = 7) and insert the result (7).
    So the result of the multiplication is:
      6829 6086 8214 4276

  • Now, add all of the digits together i.e sum is:
    6+8+2+9+ 6+0+8+6+ 8+2+1+4+ 4+2+7+6=79

  • If the credit is valid, this number(sum) is exactly divisible by 10 i.e. modulus 10 the sum is 0. Since 79 is not exactly divisible by 10, this number 4819 3046 4254 2286 is not a valid credit card.

Requirements

  • Evaluate the input number and return if the number is VALID or INVALID.

Input

  • The input number to validate as a credit card.

Output 

  • Display VALID if the input number does comply with credit card number rules else INVALID.

Test cases

No.
Input - Number (Creditcard)
Output- (VALID or INVALID)
1
4819304642542286
INVALID
2
5105105105105100
VALID
3
4111111111111111
VALID
4
378282246310000
INVALID

Instructions 

  • Accept the input number a command-line argument.
  • Write the logic to determine if the number is a valid credit card.
  • Display the resulting output.