| Author |
Topic Search Topic Options
|
Ali_GGL
Newbie
Joined: 06 November 2007
Status: Offline
Points: 7
|
Topic: Validate credit card number using JavaScript. Posted: 03 March 2008 at 11:58am |
|
Hi Any one knows how to validate a valid credit card number using JavaScript and what are the rules to be follow while
making logic please guide me as soon as possible. Thanks.
Ali.
|
 |
WebWiz-Bruce
Admin Group
Web Wiz Developer
Joined: 03 September 2001
Location: Bournemouth
Status: Offline
Points: 9844
|
Posted: 03 March 2008 at 12:27pm |
|
Credit card numbers are usually 16 digit's long so thats the first thing to test for.
All the credit card companies generate their 16 digit card numbers using a different calculation.
I was taught at college many, many, years ago exactly how so do not remember the exact details, but each card company is different. You basically run some mathematical equation on the 16 digit number and which should leave you with a base number such as '11'
|
|
|
 |
michael
Senior Member
Joined: 08 April 2002
Location: United States
Status: Offline
Points: 4670
|
Posted: 03 March 2008 at 1:26pm |
It's actually not quite that difficult. The actually number consist of the first 6 being the Bank identification Number (BIN) (Visa, MC etc have ranges of BIN's), for CC's the next 9 are the account number of the customer and the last is a control digit based on the LUHN formula (Modulus of 10).
Wikipedia on Luhn formula wrote:
- Counting from rightmost digit (which is the check digit) and moving left,
double the value of every even-positioned digit. For any digits that thus become
10 or more, take the two numbers and add them together. For example, 1111
becomes 2121, while 8763 becomes 7733 (from 2×6=12 → 1+2=3 and 2×8=16 → 1+6=7).
- Add all these digits together. For example, if 1111 becomes 2121, then
2+1+2+1 is 6; and 8763 becomes 7733, so 7+7+3+3 is 20.
- If the total ends in 0 (put another way, if the total modulus 10 is
congruent to 0), then the number is valid according to the Luhn formula; else it
is not valid. So, 1111 is not valid (as shown above, it comes out to 6), while
8763 is valid (as shown above, it comes out to 20).
|
|
|
|
 |
123Simples
Senior Member
Joined: 08 July 2007
Location: United Kingdom
Status: Offline
Points: 1192
|
Posted: 18 March 2008 at 4:58pm |
|
http://www.csgnetwork.com/directcccheckvalidate.html
It can validate whether a card number is
the right length to be a credit card number and contains the correct
check digit. Numbers accepted by this code COULD be valid credit card
numbers but may not actually correspond to a card that has been issued.
Cards rejected by the routine are definitely not valid
|
|
|
 |
dngee
Newbie
Joined: 15 July 2008
Status: Offline
Points: 2
|
Posted: 15 July 2008 at 10:49pm |
michael wrote:
It's actually not quite that difficult. The actually number consist of the first 6 being the Bank identification Number (BIN) (Visa, MC etc have ranges of BIN's), for CC's the next 9 are the account number of the customer and the last is a control digit based on the LUHN formula (Modulus of 10). [Quote=Wikipedia on Luhn formula]
- Counting from rightmost digit (which is the check digit) and moving left,
double the value of every even-positioned digit. For any digits that thus become
10 or more, take the two numbers and add them together. For example, 1111
becomes 2121, while 8763 becomes 7733 (from 2×6=12 → 1+2=3 and 2×8=16 → 1+6=7).
- Add all these digits together. For example, if 1111 becomes 2121, then
2+1+2+1 is 6; and 8763 becomes 7733, so 7+7+3+3 is 20.
- If the total ends in 0 (put another way, if the total modulus 10 is
congruent to 0), then the number is valid according to the Luhn formula; else it
is not valid. So, 1111 is not valid (as shown above, it comes out to 6), while
8763 is valid (as shown above, it comes out to 20).
|
You're very knowledgeable on this one! I don't see why this problem was Java specific, i'd think the instructions are the same in every language and you just change the syntax!
|
 |