Validate credit card number using JavaScript.
Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Web Design Discussion
Forum Description: Discussion on web design and development subjects.
URL: https://forums.webwiz.net/forum_posts.asp?TID=25384
Printed Date: 29 March 2026 at 7:00pm Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com
Topic: Validate credit card number using JavaScript.
Posted By: Ali_GGL
Subject: Validate credit card number using JavaScript.
Date 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.
------------- I am the learner for web based technologies and wants more to get.
http://www.globalguideline.com
|
Replies:
Posted By: WebWiz-Bruce
Date 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'
------------- https://www.webwiz.net/web-wiz-forums/forum-hosting.htm" rel="nofollow - Web Wiz Forums Hosting https://www.webwiz.net/web-hosting/windows-web-hosting.htm" rel="nofollow - ASP.NET Web Hosting
|
Posted By: michael
Date 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).
|
------------- http://baumannphoto.com" rel="nofollow - Blog | http://mpgtracker.com" rel="nofollow - MPG Tracker
|
Posted By: 123Simples
Date 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
------------- http://www.123simples.com/" rel="nofollow - Visit 123 Simples Web Design
|
Posted By: dngee
Date 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!
------------- http://www.breadmarket.co.uk/credit/creditcards-with-bad-credit.php - credit card with bad credit
|
|