开发教室
程序设计|Delphi|Java|C++|VB|.NET|Css|Js|PHP|ASP|MySQL|数据库|WEB开发|网页特效|视频
首页 > 开发教室 > 程序设计 > VB > 正文

决定信用卡的类型

2007-04-10 源自: 网友评论 0 进入视频教程

  Determining Credit Card Types

Need to determine a credit card type? Can注释:t be bothered to write your own decision-making function?

Fear not - hear to help is our own ready-to-run code snippet. Just feed it a credit card number and it注释:ll return a string of the appropriate card type.

If you want to determine whether a credit card number is valid, check out our handy code snippet here.

Usage

x = CreditCardType("5454 1234 4321 1234")Code

Public Function CreditCardType(ByVal CardNo As String) As String

注释:*CARD TYPES            *PREFIX           *WIDTH
注释:American Express       34, 37            15
注释:Diners Club            300 to 305, 36    14
注释:Carte Blanche          38                14
注释:Discover               6011              16
注释:EnRoute                2014, 2149        15
注释:JCB                    3                 16
注释:JCB                    2131, 1800        15
注释:Master Card            51 to 55          16
注释:Visa                   4                 13, 16
    
注释:Just in case nothing is found
CreditCardType = "Unknown"

注释:Remove all spaces and dashes from the passed string
CardNo = Replace(Replace(CardNo, " ", ""), "-", "")

注释:Check that the minimum length of the string isn注释:t less
注释:than fourteen characters and -is- numeric
If Len(CardNo) < 14 Or Not IsNumeric(CardNo) Then Exit Function

注释:Check the first two digits first
Select Case CInt(Left(CardNo, 2))
   Case 34, 37
      CreditCardType = "American Express"
   Case 36
      CreditCardType = "Diners Club"
   Case 38
      CreditCardType = "Carte Blanche"
   Case 51 To 55
      CreditCardType = "Master Card"
   Case Else

      注释:None of the above - so check the
  注释:first four digits collectively
      Select Case CInt(Left(CardNo, 4))
  
         Case 2014, 2149
            CreditCardType = "EnRoute"
         Case 2131, 1800
            CreditCardType = "JCB"
         Case 6011
            CreditCardType = "Discover"
         Case Else

            注释:None of the above - so check the
            注释:first three digits collectively
            Select Case CInt(Left(CardNo, 3))
               Case 300 To 305
                  CreditCardType = "American Diners Club"
               Case Else
         
               注释:None of the above -
               注释:so simply check the first digit
               Select Case CInt(Left(CardNo, 1))
                  Case 3
                     CreditCardType = "JCB"
                  Case 4
                    CreditCardType = "Visa"
               End Select

            End Select

      End Select
  
End Select

End Function

上一篇: 开发通信软件的技术与技巧
下一篇:用VB6.0制作多媒体影集

评论  点击查看
 
开发频道推荐
开发热点文章