Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Validate credit card number using JavaScript.
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Topic ClosedValidate credit card number using JavaScript.

 Post Reply Post Reply
Author
Ali_GGL View Drop Down
Newbie
Newbie


Joined: 06 November 2007
Status: Offline
Points: 7
Direct Link To This Post 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.
Back to Top
WebWiz-Bruce View Drop Down
Admin Group
Admin Group
Avatar
Web Wiz Developer

Joined: 03 September 2001
Location: Bournemouth
Status: Offline
Points: 9844
Direct Link To This Post 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'
Back to Top
michael View Drop Down
Senior Member
Senior Member
Avatar

Joined: 08 April 2002
Location: United States
Status: Offline
Points: 4670
Direct Link To This Post 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).
Originally posted by Wikipedia on Luhn formula Wikipedia on Luhn formula wrote:


  1. 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).
  2. 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.
  3. 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).


Back to Top
123Simples View Drop Down
Senior Member
Senior Member
Avatar

Joined: 08 July 2007
Location: United Kingdom
Status: Offline
Points: 1192
Direct Link To This Post 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
Back to Top
dngee View Drop Down
Newbie
Newbie


Joined: 15 July 2008
Status: Offline
Points: 2
Direct Link To This Post Posted: 15 July 2008 at 10:49pm
Originally posted by michael 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]
  1. 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).
  2. 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.
  3. 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!
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.