A credit card number is not a sequence of random numbers.There is an algorithm for checking if it is correct or not .
Suppose that we are going to check the credit card number 371449635398431 .Here is the step by step guide to check if a credit card number is valid or not.
1- Check for length-The length of a credit card number lies between 12 to 19.So a credit card number which has more than 19 numbers or less than 12 numbers is invalid.In my example the length is 15 characters so it passes the first test.
2- Check for digits-A valid credit card number contains only 0-9 digits.In given credit card number only numbers are appearing so it passes the second test.
3-Check validity using Modulus 10 alorithm-This is the most complex part of this tutorial so we can divide the entire process into several sub-processes.
a).Starting from right to left multiply each digit by 2.
If the number is two digits then add both digits-
Now add these numbers 6+7+6+6+9+8+5=47
b).Take the digits of credit card which are not multiplied by 2 in step a and calculated the sum.
c).Add the numbers which are obtained by step a and step b.
These three steps (a,b and c) can be easily understand by this table-
|Double every second||3||14||1||8||4||18||6||6||5||6||9||16||4||6||1||x|
|Sum of digits||3||5||1||8||4||9||6||6||5||6||9||7||4||6||1||=80|
4-Divide the number which is getting after step 3 by 10.
80/10=8 and remainder=0
If the remainder is 0 then credit card number is valid otherwise it is invalid.