1valtype::creditcard::amex(n) Validation types valtype::creditcard::amex(n)
2
3
4
5______________________________________________________________________________
6
8 valtype::creditcard::amex - Validation for AMEX 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::amex ?1?
20
21 valtype::creditcard::amex validate value
22
23 valtype::creditcard::amex checkdigit value
24
25______________________________________________________________________________
26
28 This package implements a snit validation type for an AMEX 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::amex validate .... ;# Does nothing
43 valtype::creditcard::amex validate .... ;# Throws an error (bad American Expresss 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 el‐
48 ements 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::amex 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::amex 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 er‐
63 ror 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 -er‐
68 rorcode INVALID to distinguish themselves from package internal errors.
69
70 To provide more detailed information about why the validation failed
71 the -errorCode goes actually beyond that. First, it will contain a
72 code detailing the type itself. Here this is CREDITCARD AMEX. This is
73 then followed by values detailing the reason for the failure. The full
74 set of -errorCodes which can be thrown by this package are:
75
76 INVALID CREDITCARD AMEX CHARACTER
77 The input value contained one or more bad characters, i.e. char‐
78 acters which must not occur in the input for it to be an AMEX
79 creditcard number.
80
81 INVALID CREDITCARD AMEX CHECK-DIGIT
82 The check digit of the input value is wrong. This usually sig‐
83 nals a data-entry error, with digits transposed, forgotten, etc.
84 Of course, th input may be an outright fake too.
85
86 INVALID CREDITCARD AMEX LENGTH
87 The input value is of the wrong length to be an AMEX creditcard
88 number.
89
90 INVALID CREDITCARD AMEX PREFIX
91 The input value does not start with the magic value(s) required
92 for it to be an AMEX creditcard number.
93
95 This document, and the package it describes, will undoubtedly contain
96 bugs and other problems. Please report such in the category valtype of
97 the Tcllib Trackers [http://core.tcl.tk/tcllib/reportlist]. Please
98 also report any ideas for enhancements you may have for either package
99 and/or documentation.
100
101 When proposing code changes, please provide unified diffs, i.e the out‐
102 put of diff -u.
103
104 Note further that attachments are strongly preferred over inlined
105 patches. Attachments can be made by going to the Edit form of the
106 ticket immediately after its creation, and then using the left-most
107 button in the secondary navigation bar.
108
110 AMEX, American Express, Checking, Testing, Type checking, Validation,
111 Value checking, bank, card for credit, credit card, finance, isA
112
114 Validation, Type checking
115
117 Copyright (c) 2011 Andreas Kupries <andreas_kupries@users.sourceforge.net>
118
119
120
121
122tcllib 1 valtype::creditcard::amex(n)