Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How Can I Validate Credit Cards in JavaScript?

Status
Not open for further replies.

bricenoej

Programmer
Mar 19, 2002
50
VE
Hi Everybody....
I need to apply credit card validation on my web page...

dinersclub
visa
mastercard
american express
etc

If anybody knows a function in JavaScript please paste your script for validating credit cards, or If anybody knows a WebPage.

thanks a lot friends....I appreciate that...
Eduardo(bricenoej)
 
If you want to try it, I can send you some perl code for validating a CC number (and an ABA number) that you could try to convert to javascript. None of it will actually PROVE that the number is valid, just that it is properly formed and COULD be valid. It will prevent people from entering random digits for a CC number though, since the chances of a string of random digits being a properly formed CC or ABA number is pretty small. Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
Right after I posted the above I found some code to do what you want. Unfortunately it's a little large to post here, but if you send me your email address I'll send it to you. I didn't write it, I got it from the JavaScript Source ( You could also look for it there.
Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
Hi.. tsgragon (Tracy Dryden)
Thank's for your help body!.... My e-mails are: ejbriceno@yahoo.com AND
eduardojbriceno@hotmail.com

Please send to me that code... I really appreciate that.

Greetings... Eduardo(bricenoej)
 
based on the information I found at the last url I posted here is the luhn formyla check.

<html>
<head>
<title>Luhn formula</title>
<script>

function passesLuhnTest(number)
{
var number = new String(number); // convert to a string
var digits = new Array();
var sum = 0;

for (var i = 0; i < number.length; i++)
{
digits.push(number.charAt(i))
}

digits = digits.reverse(); // easier to count from right to left

for (var i = 0; i < digits.length; i++)
{
var digit = parseInt(digits);

if (i % 2 == 0)
{
sum += digit;
}
else
{
if (digit <= 4)
{
sum += (digit * 2);
}
else
{
sum += (digit * 2) % 10 + 1;
}
}
}
return ((sum % 10) == 0)
}

alert(passesLuhnTest(49927398716))
</script>
</head>
<body>

</body>
</html> Gary Haran
 
brainjar.com also has a prewritten script: Robert Carpenter
questions? comments? thanks? email me!
linkemapx@hotmail.com
Icq: 124408594
online.dll

AIM & MSN: robacarp
 
Thanks everybody for your help!!!

Eduardo(bricenoej@yahoo.com)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top