Has anyone created a credit card validator before using xojo?
I looked at this once, but got distracted by other issues. I decided I didn’t want to go through the trouble associated with credit card transactions. It is much easier these days.
The Luhn algorithm is often used to check validity:
https://en.wikipedia.org/wiki/Luhn_algorithm
also…
https://en.wikipedia.org/wiki/Credit_card_fraud
I found this on the web - hope it helps:
This is the (visual basic) code used to create a webform that verifies the validity of a Visa credit card.
(http://jamesrbass.com/luhnSourceCode.html)
Private Sub uiVerifyButton_Click(ByVal sender As System.Object, ByVal e _
As System.EventArgs) Handles uiVerifyButton.Click
Dim possibleNum(), ccStr As String
ccStr = Me.uiCreditTextBox.Text.Replace(" ", “”)
Dim nDigits, mySum As Integer
nDigits = Len(ccStr)
ReDim possibleNum(nDigits)
If (nDigits <> 16 AndAlso nDigits <> 13) Then
View HTML source code to see what goes here.
Else
mySum = myLuhn(possibleNum, ccStr, nDigits)
If (mySum Mod 10 = 0) Then
Me.uiValidLabel.Text = "Valid Number"
Else
Me.uiValidLabel.Text = "Invalid Number"
End If
End If
End Sub
Private Function myLuhn(ByRef possNum() As String, ByRef ccStrg As String _
, ByVal nDigits As Integer) As Integer
Dim sum, parity, digit, i As Integer
parity = nDigits Mod 2
For i = 0 To nDigits - 1
possNum(i) = ccStrg.Substring(i, 1)
digit = CInt(possNum(i))
If (i Mod 2 = parity) Then
digit *= 2
End If
If (digit > 9) Then
digit -= 9
End If
sum += digit
Next i
Me.uiValidLabel.Visible = True
Return sum
End Function
If you use MBS Xojo Plugins, you can use IsValidCreditCardNumberMBS function.