1valtype::imei(n) Validation types valtype::imei(n)
2
3
4
5______________________________________________________________________________
6
8 valtype::imei - Validation for IMEI
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::imei ?1?
20
21 valtype::imei validate value
22
23 valtype::imei checkdigit value
24
25______________________________________________________________________________
26
28 This package implements a snit validation type for an IMEI.
29
30 A validation type is an object that can be used to validate Tcl values
31 of a particular kind. For example, snit::integer, a validation type
32 defined by the snit package is used to validate that a Tcl value is an
33 integer.
34
35 Every validation type has a validate method which is used to do the
36 validation. This method must take a single argument, the value to be
37 validated; further, it must do nothing if the value is valid, but throw
38 an error if the value is invalid:
39
40
41 valtype::imei validate .... ;# Does nothing
42 valtype::imei validate .... ;# Throws an error (bad International Mobile Equipment Identity (IMEI) number).
43
44
45 The validate method will always return the validated value on success,
46 and throw the -errorcode INVALID on error, possibly with additional
47 elements which provide more details about the problem.
48
50 The API provided by this package satisfies the specification of snit
51 validation types found in the documentation of Snit's Not Incr Tcl.
52
53 valtype::imei validate value
54 This method validates the value and returns it, possibly in a
55 canonical form, if it passes. If the value does not pass the
56 validation an error is thrown.
57
58 valtype::imei checkdigit value
59 This method computes a check digit for the value. Before doing
60 so it is validated, except for a checkdigit. If the value does
61 not pass the validation no check digit is calculated and an
62 error is thrown instead.
63
65 As said in the package description, the errors thrown by the commands
66 of this package in response to input validation failures use the
67 -errorcode INVALID to distinguish themselves from package internal
68 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 IMEI. This is then fol‐
73 lowed by values detailing the reason for the failure. The full set of
74 -errorCodes which can be thrown by this package are:
75
76 INVALID IMEI 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 IMEI.
79
80 INVALID IMEI CHECK-DIGIT
81 The check digit of the input value is wrong. This usually sig‐
82 nals a data-entry error, with digits transposed, forgotten, etc.
83 Of course, th input may be an outright fake too.
84
85 INVALID IMEI LENGTH
86 The input value is of the wrong length to be an IMEI.
87
89 This document, and the package it describes, will undoubtedly contain
90 bugs and other problems. Please report such in the category valtype of
91 the Tcllib Trackers [http://core.tcl.tk/tcllib/reportlist]. Please
92 also report any ideas for enhancements you may have for either package
93 and/or documentation.
94
95 When proposing code changes, please provide unified diffs, i.e the out‐
96 put of diff -u.
97
98 Note further that attachments are strongly preferred over inlined
99 patches. Attachments can be made by going to the Edit form of the
100 ticket immediately after its creation, and then using the left-most
101 button in the secondary navigation bar.
102
104 Checking, IMEI, International Mobile Equipment Identity, Testing, Type
105 checking, Validation, Value checking, cell-phone, isA, mobile phone,
106 phone
107
109 Validation, Type checking
110
112 Copyright (c) 2011 Andreas Kupries <andreas_kupries@users.sourceforge.net>
113
114
115
116
117tcllib 1 valtype::imei(n)