1valtype::creditcard::visa(n) Validation types valtype::creditcard::visa(n)
2
3
4
5______________________________________________________________________________
6
8 valtype::creditcard::visa - Validation for VISA creditcard number
9
11 package require Tcl 8.5
12
13 package require snit 2
14
15 package require valtype::common
16
17 package require valtype::luhn
18
19 package require valtype::creditcard::visa ?1?
20
21 valtype::creditcard::visa validate value
22
23 valtype::creditcard::visa checkdigit value
24
25______________________________________________________________________________
26
28 This package implements a snit validation type for a VISA creditcard
29 number.
30
31 A validation type is an object that can be used to validate Tcl values
32 of a particular kind. For example, snit::integer, a validation type
33 defined by the snit package is used to validate that a Tcl value is an
34 integer.
35
36 Every validation type has a validate method which is used to do the
37 validation. This method must take a single argument, the value to be
38 validated; further, it must do nothing if the value is valid, but throw
39 an error if the value is invalid:
40
41
42 valtype::creditcard::visa validate .... ;# Does nothing
43 valtype::creditcard::visa validate .... ;# Throws an error (bad VISA creditcard number).
44
45
46 The validate method will always return the validated value on success,
47 and throw the -errorcode INVALID on error, possibly with additional
48 elements which provide more details about the problem.
49
51 The API provided by this package satisfies the specification of snit
52 validation types found in the documentation of Snit's Not Incr Tcl.
53
54 valtype::creditcard::visa validate value
55 This method validates the value and returns it, possibly in a
56 canonical form, if it passes. If the value does not pass the
57 validation an error is thrown.
58
59 valtype::creditcard::visa checkdigit value
60 This method computes a check digit for the value. Before doing
61 so it is validated, except for a checkdigit. If the value does
62 not pass the validation no check digit is calculated and an
63 error is thrown instead.
64
66 As said in the package description, the errors thrown by the commands
67 of this package in response to input validation failures use the
68 -errorcode INVALID to distinguish themselves from package internal
69 errors.
70
71 To provide more detailed information about why the validation failed
72 the -errorCode goes actually beyond that. First, it will contain a
73 code detailing the type itself. Here this is CREDITCARD VISA. This is
74 then followed by values detailing the reason for the failure. The full
75 set of -errorCodes which can be thrown by this package are:
76
77 INVALID CREDITCARD VISA CHARACTER
78 The input value contained one or more bad characters, i.e. char‐
79 acters which must not occur in the input for it to be a VISA
80 creditcard number.
81
82 INVALID CREDITCARD VISA CHECK-DIGIT
83 The check digit of the input value is wrong. This usually sig‐
84 nals a data-entry error, with digits transposed, forgotten, etc.
85 Of course, th input may be an outright fake too.
86
87 INVALID CREDITCARD VISA LENGTH
88 The input value is of the wrong length to be a VISA creditcard
89 number.
90
91 INVALID CREDITCARD VISA PREFIX
92 The input value does not start with the magic value(s) required
93 for it to be a VISA creditcard number.
94
96 This document, and the package it describes, will undoubtedly contain
97 bugs and other problems. Please report such in the category valtype of
98 the Tcllib Trackers [http://core.tcl.tk/tcllib/reportlist]. Please
99 also report any ideas for enhancements you may have for either package
100 and/or documentation.
101
102 When proposing code changes, please provide unified diffs, i.e the out‐
103 put of diff -u.
104
105 Note further that attachments are strongly preferred over inlined
106 patches. Attachments can be made by going to the Edit form of the
107 ticket immediately after its creation, and then using the left-most
108 button in the secondary navigation bar.
109
111 Checking, Testing, Type checking, VISA, Validation, Value checking,
112 bank, card for credit, credit card, finance, isA
113
115 Validation, Type checking
116
118 Copyright (c) 2011 Andreas Kupries <andreas_kupries@users.sourceforge.net>
119
120
121
122
123tcllib 1 valtype::creditcard::visa(n)