Credit Card Validation

  • Thread starter Thread starter Grant
  • Start date Start date
G

Grant

Does any one know how to check the algorithm of the credit card number that
was entered in the text box? I want to be able to make sure the users enter
correct credit card number since we will process it manually via phone. I
want this to be done on the server side behind the code in ASP.Net. Thanks
 
I have a credit card validation sample on my web site in the code library:
www.aboutfortunate.com

It's titled: Regular expression credit card validation. I haven't
implemented a way to search the database yet, but if you set the first drop
down list to: Web or Windows, and the second drop down to: JavaScript it
will limit the library to just that entry.

--
S. Justin Gengo
Web Developer / Programmer

Free Code Library At:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
 
Here is an access function for generic card testing which might help you
also.

Function CreditCardCheckDigit(strCreditCard As String) As Boolean
Dim intLength As Integer
Dim intEvenSum As Integer
Dim intOddSum As Integer
Dim i As Integer
CreditCardCheckDigit = False
On Error GoTo Errorhandler
intEvenSum = 0
intOddSum = 0
intLength = Len(strCreditCard)
If intLength Mod 2 = 1 Then strCreditCard = "0" & strCreditCard ' for
amex
For i = 1 To intLength - 1
If i Mod 2 = 0 Then
intEvenSum = intEvenSum + CInt(Mid(strCreditCard, i, 1))
ElseIf CInt(Mid(strCreditCard, i, 1)) = 9 Then
intOddSum = intOddSum + 9
Else
intOddSum = intOddSum + CInt(Mid(strCreditCard, i, 1)) * 2 Mod 9
End If
Next i
If Right(CStr(1000 - (intEvenSum + intOddSum)), 1) =
CInt(Right(strCreditCard, 1)) Then
CreditCardCheckDigit = True
End If


Exit Function
Errorhandler:
MsgBox "Credit Card Check Digit function failed."

End Function
 
Client Side JavaScript (quite full featured):
http://freshmeat.net/releases/112097/

Someone has already posted a VB.NET version, so no need to go there. I have
a C# version somewhere, if that is a need.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
Author: ADO.NET and XML: ASP.NET on the Edge

****************************************************************************
****
Think Outside the Box!
****************************************************************************
****
 
Someone has already posted a VB.NET version, so no need to go there. I have
a C# version somewhere, if that is a need.
I would greatly appreciate the C# version :))
Ron
 
Ron:

I have tweaked the Mod10 to make it a bit cleaner (the original was
converted from a VB project):

public bool CheckMod10(string cardNumber)
{
char[] cardNums = cardNumber.Trim().ToCharArray();
int cardLength = cardNums.Length;
bool lengthCardEven = ((cardNums.Length%2)==0);
int checkValue=0;
int currentValue=0;

for(int counter=0;counter<cardNums.Length;counter++)
{

if((((counter%2)==0)&&(lengthCardEven))||(((counter%2)==1)&&(!lengthCardEven
)))
currentValue = Convert.ToInt32(cardNums[counter].ToString())*2;
else
currentValue = Convert.ToInt32(cardNums[counter].ToString());

if(currentValue>=10)
currentValue -= 9;

checkValue += currentValue;
}

return checkValue%10==0 ? true : false;
}

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
Author: ADO.NET and XML: ASP.NET on the Edge

****************************************************************************
****
Think Outside the Box!
****************************************************************************
****
 
Back
Top