credit card validater. i won't validate card no, cvv and ex date.

  • Thread starter Thread starter A.S.Hasanka
  • Start date Start date
A

A.S.Hasanka

Guest
this i try.. but it doesn't work.. please help


Private _left As Integer
Private _right As Integer


Private Property Left(CardNumber As String, p2 As Integer) As Integer
Get
Return _left
End Get
Set(value As Integer)
_left = value
End Set
End Property

Private Property Right(intArrValue As Integer, p2 As Integer) As Integer
Get
Return _right
End Get
Set(value As Integer)
_right = value
End Set
End Property

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
End Sub





' (None)

Private Function ccchecker(ByVal value As String) As Boolean

Dim checksum As Integer = 0
Dim doubleflag As Boolean = (value.Length Mod 2 = 0)
Dim ccnumber As Char
Dim ccnumbervalue As Integer

For Each ccnumber In value
ccnumbervalue = Integer.Parse(ccnumber)
If doubleflag Then
ccnumbervalue *= 2
If ccnumbervalue > 9 Then
ccnumbervalue -= 9
End If
End If
checksum += ccnumbervalue
doubleflag = Not doubleflag
Next
Return (checksum Mod 10 = 0)
End Function



Public Function ValidCard(ByVal CardNumber As String) As Boolean

Dim intCount As Integer
Dim intValue As Integer
Dim intArr() As Integer
Dim intStart As Integer
Dim intArrValue As Integer

ValidCard = False

If Not IsNumeric(CardNumber) Then Exit Function

If Left(CardNumber, 4) = 2131 Or Left(CardNumber, 4) _
= 1800 Then
'JCB
If Len(CardNumber) <> 15 Then Exit Function
ElseIf Left(CardNumber, 4) = 2149 Or _
Left(CardNumber, 4) = 2014 Then
'enroute
If Len(CardNumber) = 15 Then
ValidCard = True
End If
Exit Function
ElseIf Left(CardNumber, 4) = 6011 Then
'discover
If Len(CardNumber) <> 16 Then Exit Function
ElseIf (Left(CardNumber, 3) >= 300 And _
Left(CardNumber, 3) <= 305) Or _
Left(CardNumber, 2) = 36 Or Left(CardNumber, 2) = 38 Then
'diners club
If Len(CardNumber) <> 14 Then Exit Function
ElseIf Left(CardNumber, 2) = 34 Or _
Left(CardNumber, 2) = 37 Then
'amex
If Len(CardNumber) <> 15 Then Exit Function
ElseIf Left(CardNumber, 2) >= 51 And _
Left(CardNumber, 2) <= 55 Then
'mastercard
If Len(CardNumber) <> 16 Then Exit Function
ElseIf Left(CardNumber, 1) = 4 Then
'visa
If Not (Len(CardNumber) = 13 Or Len(CardNumber) = 16) _
Then Exit Function
ElseIf Left(CardNumber, 1) = 3 Then
'jcb (2)
If Len(CardNumber) <> 16 Then Exit Function
Else
'unknown card.....
Exit Function
End If
ReDim intArr(Len(CardNumber))
For intCount = Len(CardNumber) - 1 To 1 Step -2
intValue = Mid(CardNumber, intCount, 1) * 2
intArr(intCount) = intValue
Next intCount

intValue = 0

If Len(CardNumber) Mod 2 = 0 Then
intStart = 2
Else
intStart = 1
End If

For intCount = intStart To Len(CardNumber) Step 2
intValue = intValue + Mid(CardNumber, intCount, 1)
intArrValue = intArr(intCount - 1)
If intArrValue < 10 Then
intValue = intValue + intArrValue
Else
intValue = intValue + Left(intArrValue, 1) + _
Right(intArrValue, 1)
End If
Next intCount

If intValue Mod 10 <> 0 Then
Exit Function
Else
ValidCard = True
End If



If TextBox1.Text <> "" Then
If TextBox2.Text = "" And DateTimePicker1.Text = "" Then
MsgBox("This card has been validated as a correct card number!", MsgBoxStyle.Information)
Else
MsgBox("This card has been validated as an incorrect card number", MsgBoxStyle.Critical)
End If
Else
MsgBox("textbox1 cannot be empty")
TextBox1.Select()
End If

Continue reading...
 
Back
Top