dcsimg
October 15, 2018
Hot Topics:

TIP: Validating Credit Card Numbers

  • September 20, 2002
  • By Sam Huggill
  • Send Email »
  • More Articles »
Function CheckCard(CCNumber As String) _
            As Boolean
Dim Counter As Integer, TmpInt As Integer
Dim Answer As Integer

Counter = 1
TmpInt = 0

While Counter <= Len(CCNumber)

If IsEven(Len(CCNumber)) Then
  TmpInt = Val(Mid$(CCNumber, Counter, 1))
  If Not IsEven(Counter) Then
    TmpInt = TmpInt * 2
    If TmpInt > 9 Then TmpInt = TmpInt - 9
  End If
  Answer = Answer + TmpInt
  'Debug.Print Counter, TmpInt, Answer
  Counter = Counter + 1
Else
  TmpInt = Val(Mid$(CCNumber, Counter, 1))
  If IsEven(Counter) Then
    TmpInt = TmpInt * 2
    If TmpInt > 9 Then TmpInt = TmpInt - 9
  End If
  Answer = Answer + TmpInt
  'Debug.Print Counter, TmpInt, Answer
  Counter = Counter + 1
End If

Wend

Answer = Answer Mod 10

If Answer = 0 Then CheckCard = True
End Function

Private Sub cmdCheck_Click()
Msgbox CheckCard(txtNumber)
End Sub





Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

By submitting your information, you agree that developer.com may send you developer offers via email, phone and text message, as well as email offers about other products and services that developer believes may be of interest to you. developer will process your information in accordance with the Quinstreet Privacy Policy.

Sitemap

Thanks for your registration, follow us on our social networks to keep up-to-date