Saturday, April 18, 2009

Script Validasi dan Type Credit Card

Script Untuk VALIDASI dan menentukan TYPE credit card.

Sub ValidateCC(Sender As Object, E As EventArgs)
Dim ccText As String = CreditNo.Text '-- nomor credit card
Dim indicator As Integer = 1
Dim firstNumToAdd As Integer = 0 '-- total 1
Dim secondNumToAdd As Integer = 0 '-- total 2
Dim num1 As String
Dim num2 As String
Dim ccArr As Char() = ccText.ToCharArray()
Dim i As Integer
For i = ccArr.Length - 1 To 0 Step -1
Dim ccNoAdd As Char = ccArr(i)
Dim ccAdd As Integer = Int32.Parse(ccNoAdd.ToString())
If indicator = 1 Then
firstNumToAdd += ccAdd
indicator = 0
Else
If ccAdd + ccAdd >= 10 Then
Dim temporary As Integer = ccAdd + ccAdd
num1 = temporary.ToString().Substring(0, 1)
num2 = temporary.ToString().Substring(1, 1)
secondNumToAdd += Convert.ToInt32(num1) + Convert.ToInt32(num2)
Else
secondNumToAdd += ccAdd + ccAdd
End If
indicator = 1
End If
Next i
If(firstNumToAdd + secondNumToAdd) Mod 10 = 0 Then
Result.Text = "This Card Is Valid"
CCType.Text = RetrieveCCType(ccText)
Else
Result.Text = "This Card Is Invalid"
End If
End Sub
Function RetrieveCCType(CCNum As String) As String
If Convert.ToInt32(CCNum.Substring(0, 2)) >= 51 And Convert.ToInt32(CCNum.Substring(0, 2)) <= 55 Then
Return "This card is a Master Card."
End If
If Convert.ToString(CCNum.Substring(0, 1)) = "4" Then
Return "This card is a Visa."
End If
If Convert.ToString(CCNum.Substring(0, 2)) = "34" Or Convert.ToString(CCNum.Substring(0, 2)) = "37" Then
Return "This card is an American Express."
End If
If Convert.ToString(CCNum.Substring(0, 4)) = "6011" Then
Return "This card is a Discover Card."
End If
Return "This is an unknown credit card."
End Function

/*from : banyak artikel di google*/

0 komentar:

Post a Comment

 
© Copyright by :.  |  Template by Blogspot tutorial