Validating numbers example

Last Updated : Sep 08, 2012 |
The XYZ company wants a write a vector subroutine that validates a credit card number before a query is sent to the appropriate credit card company for their validation.
The XYZ company created a subroutine that does the following tasks:
  1. Prompt the user for the type of credit card used for the purchase.
    • 1 - diners club
    • 2 - american express
    • 3 - visa
    • 4 - master card
    • 5 - discover
  2. If a valid card type (1-5) is entered, prompt for the credit card number.
  3. Validate the first four digits of each card number prefix.
    The following table provides a list of card number identifiers and card number lengths for the major credit card companies.
    Company
    Card number identifier
    Card length
    Diner’s Club or Carte Blanche
    300xxxxxxxxxxx
    305xxxxxxxxxxx
    36xxxxxxxxxxxx
    38xxxxxxxxxxxx
    14
    American Express
    34xxxxxxxxxxxxx
    37xxxxxxxxxxxxx
    15
    VISA
    4xxxxxxxxxxxx
    4xxxxxxxxxxxxxxx
    13, 16
    MasterCard
    51xxxxxxxxxxxxxx
    55xxxxxxxxxxxxxx
    16
    Discover
    6011xxxxxxxxxxxx
    16
  4. Perform a Luhn or Modulus 10 check on the whole number.
  5. If the validation fails validation, indicate that the card number entered is invalid and prompt again for the credit card type.
  6. If the card validates, return and let variable A contain the type of card, and the digits buffer contain the validated credit card number.

Examples

                            VARIABLES FOR VECTORS

Var Description                 Type    Scope Length Start Assignment       VAC

A   credit card type            collect L     1      1                     
B   4 digit prefix of cred card collect L     4      1                     
C   modulus 10 result           collect L     1      1

                                  CALL VECTOR

    Number: 3                Name: credit card chk
                                             Meet-me Conf? n           Lock? n
     Basic? y   EAS? y   G3V4 Enhanced? y   ANI/II-Digits? n   ASAI Routing? y
 Prompting? y   LAI? n  G3V4 Adv Route? y   CINFO? n   BSR? y   Holidays? y
 Variables? y   3.0 Enhanced? y
01 collect      1    digits after announcement 4501     for A 
  (Prompt for credit card type, 1-diners, 2-american, 3-visa, 4-mc, 5-discover)
02 collect      16   digits after announcement 4502     for B
  (Prompt for credit card number followed by #)
03 goto step   7           if B                in     table A  
  (check if credit card prefix matches appropriate card type)
04 announcement 4503        (Bad number,Try again)
05 goto step   1           if unconditionally  
06             
07 goto step   13          if A                =      1 (Diners Club)
08 goto step   17          if A                =      2 (American Express)
09 goto step   20          if A                =      3 (Visa)
10 goto step   22          if A                >=     4 (Master Card, Discover)
11 goto step   1           if unconditionally  (unknown)
12             
13 set          C      = digits MOD10 14      (Diners Club, check)
14 goto step   1           if C                <>     0 (not valid, try again)
15 return             (OKAY! VALID! RETURN!
                                digits buffer contains
                                valid creditcard number)
16 
17 set          C      = digits MOD10 15      (American Express)
18 goto step   14          if unconditionally 
19             
20 set          C      = digits MOD10 13      (Visa check 13 digits)
21 goto step   15          if C                =      0 (OKAY! VALID! RETURN!)
22 set          C      = digits MOD10 16      (VISA, MASTER CARD,
                                          DISCOVER chk 16 digits)
23 goto step   14          if unconditionally

add vrt 1                                                       Page   1 of   3 

                              VECTOR ROUTING TABLE

      Number: 1       Name: Diners Club         Sort? n

           1: 300?
           2: 301?
           3: 302?
           4: 303?
           5: 304?
           6: 305?
           7: 36??
           8: 38??
--------------------------------------------------------------------------------
add vrt 2                                                       Page   1 of   3 
                              VECTOR ROUTING TABLE

      Number: 2       Name: American Express    Sort? n
           1: 34??
           2: 37??
--------------------------------------------------------------------------------
add vrt 3                                                       Page   1 of   3 
                              VECTOR ROUTING TABLE

      Number: 3       Name: VISA                Sort? n
           1: 4???
--------------------------------------------------------------------------------
add vrt 4                                                       Page   1 of   3 
                              VECTOR ROUTING TABLE

      Number: 4       Name: MASTER CARD         Sort? n
           1: 51??
           2: 52??
           3: 53??
           4: 54??
           5: 55??
--------------------------------------------------------------------------------
add vrt 5                                                       Page   1 of   3 
                              VECTOR ROUTING TABLE

      Number: 5       Name: MASTER CARD         Sort? n
           1: 6011
----------------------------------------------------------------------------