469,645 Members | 1,150 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,645 developers. It's quick & easy.

Credit Card Validation



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
Nov 17 '05 #1
6 10770
Take a look at this site.

http://www.merriampark.com/anatomycc.htm

"Grant" <Gr***@nutrikids.com> wrote in message
news:u$**************@tk2msftngp13.phx.gbl...


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

Nov 17 '05 #2
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
"Grant" <Gr***@nutrikids.com> wrote in message
news:u$**************@tk2msftngp13.phx.gbl...


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

Nov 17 '05 #3
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
"Grant" <Gr***@nutrikids.com> wrote in message
news:u$**************@tk2msftngp13.phx.gbl...


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

Nov 17 '05 #4
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!
************************************************** **************************
****
"Grant" <Gr***@nutrikids.com> wrote in message
news:u$**************@tk2msftngp13.phx.gbl...


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

Nov 17 '05 #5
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
Nov 17 '05 #6
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))||(((counte r%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!
************************************************** **************************
****
"Ron C." <rc*****@net9.cc> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
many thanks
Ron

Nov 17 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by kaptain kernel | last post: by
10 posts views Thread by dries | last post: by
4 posts views Thread by Michelle A. | last post: by
7 posts views Thread by Sandy | last post: by
3 posts views Thread by tshad | last post: by
1 post views Thread by securedcardss | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.