How to Validate Visa Card Numbers
Visa card numbers, as well as most other credit card numbers, can be validated using the Luhn algorithm (also known as the Luhn formula or the “mod 10” or “modulus 10” algorithm).
It is a very simple procedure, which verifies the card number in the following fashion:
 Double the value of the card number’s every odd digit. If the resulting sum of each doubling operation is greater than 9 (for example, 6 x 2 = 12), then add the digits of the sum (e.g., 12: 1 + 2 = 3 or 16: 1 + 6 = 7).
 Add up all the resulting digits, including the ones you did not multiply by two.
 If the total you received ends in 0, the card number is valid according to the Luhn algorithm; otherwise it is not valid.
For example, let’s validate the following Visa number: “4024007191315703”. Here is what we get when we follow the threestep process I’ve just described:
Account number 
4 
0 
2 
4 
0 
0 
7 
1 
9 
1 
3 
1 
5 
7 
0 
3 

Double every odd digit 
8 
0 
4 
4 
0 
0 
14 
1 
18 
1 
6 
1 
10 
7 
0 
3 

Sum 
8 
0 
4 
4 
0 
0 
5 
1 
9 
1 
6 
1 
1 
7 
0 
3 
50 
The end result — 50 — ends in 0, which means that our number passes the Luhn formula test.
Of course, the card number’s validity does not preclude the possibility that the card may still be counterfeit, so you will need to follow the best card acceptance practices I’ve outlined below.
Well in the example its 40 not 50
The sum is 50, not 40, even though it would make no difference.