- Namespace ecommerce
-
- Public Class Valide_CB
-
- Private tmp_digits As String = "0123456789"
-
- Public Function CardValidate(ByVal DDLtypeCarte As String, ByVal TxtNumCarte As String) As Boolean
- Dim bValid As Boolean
-
- If (DDLtypeCarte = "VISA" Or DDLtypeCarte = "CarteBleue") Then
- Dim totalcarte As Integer = 0
- Dim increment As Integer = 0
-
- If Len(TxtNumCarte) <> 16 Then
- bValid = False
- Exit Function
- End If
- Dim i As Integer
- Dim numero As Integer
- For i = Len(TxtNumCarte) To 1 Step -1
- numero = CInt(Mid(TxtNumCarte, i, 1))
- increment = increment + 1
-
- If increment Mod 2 <> 0 Then
- totalcarte = totalcarte + numero
- Else
- numero = numero * 2
- If numero >= 10 Then
- totalcarte = totalcarte + 1 + numero - 10
- Else
- totalcarte = totalcarte + numero
- End If
- End If
- Next
-
- If totalcarte Mod 10 <> 0 Then
- bValid = False
- Else
- bValid = True
- End If
- ElseIf DDLtypeCarte = "EuroCard" Then
- bValid = True
- Dim number As String = ""
- ' make sure there are only numbers in the string...
- number = fKeepOnlyDigits(TxtNumCarte)
- Dim chiffre1 As String = Mid(number, 1, 1)
- Dim chiffre2 As String = Mid(number, 2, 1)
- Dim longueur As Integer = Len(number)
- If chiffre1 <> "5" Or chiffre2 < "1" Or chiffre2 > "5" Then
- bValid = False
- End If
- '--| anne : longueur du numero carte > 16
- 'if longueur = 16 then
- If longueur <> 16 Then
- bValid = False
- End If
- End If
- Return bValid
- End Function
-
- Public Function fKeepOnlyDigits(ByVal TxtNumCarte As String) As String
- Dim sResults As String = TxtNumCarte
- Dim i As Integer = 1
- While i <= Len(sResults)
- If InStr(tmp_digits, Mid(sResults, i, 1)) > 0 Then
- i = i + 1
- Else
- sResults = Left(sResults, i - 1) + Mid(sResults, i + 1)
- End If
- End While
- Return sResults
- End Function
- End Class
-
- End Namespace
Namespace ecommerce
Public Class Valide_CB
Private tmp_digits As String = "0123456789"
Public Function CardValidate(ByVal DDLtypeCarte As String, ByVal TxtNumCarte As String) As Boolean
Dim bValid As Boolean
If (DDLtypeCarte = "VISA" Or DDLtypeCarte = "CarteBleue") Then
Dim totalcarte As Integer = 0
Dim increment As Integer = 0
If Len(TxtNumCarte) <> 16 Then
bValid = False
Exit Function
End If
Dim i As Integer
Dim numero As Integer
For i = Len(TxtNumCarte) To 1 Step -1
numero = CInt(Mid(TxtNumCarte, i, 1))
increment = increment + 1
If increment Mod 2 <> 0 Then
totalcarte = totalcarte + numero
Else
numero = numero * 2
If numero >= 10 Then
totalcarte = totalcarte + 1 + numero - 10
Else
totalcarte = totalcarte + numero
End If
End If
Next
If totalcarte Mod 10 <> 0 Then
bValid = False
Else
bValid = True
End If
ElseIf DDLtypeCarte = "EuroCard" Then
bValid = True
Dim number As String = ""
' make sure there are only numbers in the string...
number = fKeepOnlyDigits(TxtNumCarte)
Dim chiffre1 As String = Mid(number, 1, 1)
Dim chiffre2 As String = Mid(number, 2, 1)
Dim longueur As Integer = Len(number)
If chiffre1 <> "5" Or chiffre2 < "1" Or chiffre2 > "5" Then
bValid = False
End If
'--| anne : longueur du numero carte > 16
'if longueur = 16 then
If longueur <> 16 Then
bValid = False
End If
End If
Return bValid
End Function
Public Function fKeepOnlyDigits(ByVal TxtNumCarte As String) As String
Dim sResults As String = TxtNumCarte
Dim i As Integer = 1
While i <= Len(sResults)
If InStr(tmp_digits, Mid(sResults, i, 1)) > 0 Then
i = i + 1
Else
sResults = Left(sResults, i - 1) + Mid(sResults, i + 1)
End If
End While
Return sResults
End Function
End Class
End Namespace