What's Here?
- Members: 131,099
- Replies: 468,506
- Topics: 72,572
- Snippets: 2,532
- Tutorials: 661
- Total Online: 2,136
- Members: 63
- Guests: 2,073
Who's Online?
|
A function that validates a credit card based on the LUHN10 algorithm. This function does not care if the number is a visa, mastercard, etc. etc.
|
Submitted By: skyhawk133
|
|
Rating:

|
|
Views: 12,167 |
Language: JavaScript
|
|
Last Modified: March 29, 2005 |
|
Instructions: Pass the credit card number to the function, if it's valid true will be returned, if not, false will be returned. |
Snippet
/*---------------------------------------------------------------*/
/* */
/* Function : isCreditCard() */
/* Purpose : Check if cc is LUHN10 */
/* */
/* */
/* Parameters: cc - the cc number */
/* */
/* Returns : boolean */
/* */
/* Usage : isCreditCard(cc) */
/*---------------------------------------------------------------*/
function isCreditCard( CC )
{
if (CC.length > 19)
return (false);
sum = 0; mul = 1; l = CC.length;
for (i = 0; i < l; i++)
{
digit = CC.substring(l-i-1,l-i);
tproduct = parseInt(digit ,10)*mul;
if (tproduct >= 10)
sum += (tproduct % 10) + 1;
else
sum += tproduct;
if (mul == 1)
mul++;
else
mul--;
}
if ((sum % 10) == 0)
return (true);
else
return (false);
}
Copy & Paste
|
|
|
Programming
Web Development
Reference Sheets
Bye Bye Ads
Free DIC T-Shirt
Related Sites
Monthly Drawing
Partners
Top Contributors
Top 10 Kudos This Month
|