1
2[//000000001]: # (valtype::imei \- Validation types)
3[//000000002]: # (Generated from file 'vtype\.inc' by tcllib/doctools with format 'markdown')
4[//000000003]: # (Copyright &copy; 2011 Andreas Kupries <andreas\_kupries@users\.sourceforge\.net>)
5[//000000004]: # (valtype::imei\(n\) 1 tcllib "Validation types")
6
7<hr> [ <a href="../../../../toc.md">Main Table Of Contents</a> &#124; <a
8href="../../../toc.md">Table Of Contents</a> &#124; <a
9href="../../../../index.md">Keyword Index</a> &#124; <a
10href="../../../../toc0.md">Categories</a> &#124; <a
11href="../../../../toc1.md">Modules</a> &#124; <a
12href="../../../../toc2.md">Applications</a> ] <hr>
13
14# NAME
15
16valtype::imei \- Validation for IMEI
17
18# <a name='toc'></a>Table Of Contents
19
20  - [Table Of Contents](#toc)
21
22  - [Synopsis](#synopsis)
23
24  - [Description](#section1)
25
26  - [API](#section2)
27
28  - [Error Codes](#section3)
29
30  - [Bugs, Ideas, Feedback](#section4)
31
32  - [Keywords](#keywords)
33
34  - [Category](#category)
35
36  - [Copyright](#copyright)
37
38# <a name='synopsis'></a>SYNOPSIS
39
40package require Tcl 8\.5
41package require snit 2
42package require valtype::common
43package require valtype::luhn
44package require valtype::imei ?1?
45
46[__valtype::imei__ __validate__ *value*](#1)
47[__valtype::imei__ __checkdigit__ *value*](#2)
48
49# <a name='description'></a>DESCRIPTION
50
51This package implements a snit validation type for an IMEI\.
52
53A validation type is an object that can be used to validate Tcl values of a
54particular kind\. For example, __snit::integer__, a validation type defined
55by the __[snit](\.\./snit/snit\.md)__ package is used to validate that a
56Tcl value is an integer\.
57
58Every validation type has a __validate__ method which is used to do the
59validation\. This method must take a single argument, the value to be validated;
60further, it must do nothing if the value is valid, but throw an error if the
61value is invalid:
62
63    valtype::imei validate .... ;# Does nothing
64    valtype::imei validate .... ;# Throws an error (bad International Mobile Equipment Identity (IMEI) number).
65
66The __validate__ method will always return the validated value on success,
67and throw the __\-errorcode__ INVALID on error, possibly with additional
68elements which provide more details about the problem\.
69
70# <a name='section2'></a>API
71
72The API provided by this package satisfies the specification of snit validation
73types found in the documentation of *[Snit's Not Incr
74Tcl](\.\./snit/snit\.md)*\.
75
76  - <a name='1'></a>__valtype::imei__ __validate__ *value*
77
78    This method validates the *value* and returns it, possibly in a canonical
79    form, if it passes\. If the value does not pass the validation an error is
80    thrown\.
81
82  - <a name='2'></a>__valtype::imei__ __checkdigit__ *value*
83
84    This method computes a check digit for the *value*\. Before doing so it is
85    validated, except for a checkdigit\. If the value does not pass the
86    validation no check digit is calculated and an error is thrown instead\.
87
88# <a name='section3'></a>Error Codes
89
90As said in the package description, the errors thrown by the commands of this
91package in response to input validation failures use the __\-errorcode__
92INVALID to distinguish themselves from package internal errors\.
93
94To provide more detailed information about why the validation failed the
95__\-errorCode__ goes actually beyond that\. First, it will contain a code
96detailing the type itself\. Here this is __IMEI__\. This is then followed by
97values detailing the reason for the failure\. The full set of __\-errorCode__s
98which can be thrown by this package are:
99
100  - INVALID IMEI CHARACTER
101
102    The input value contained one or more bad characters, i\.e\. characters which
103    must not occur in the input for it to be an IMEI\.
104
105  - INVALID IMEI CHECK\-DIGIT
106
107    The check digit of the input value is wrong\. This usually signals a
108    data\-entry error, with digits transposed, forgotten, etc\. Of course, th
109    input may be an outright fake too\.
110
111  - INVALID IMEI LENGTH
112
113    The input value is of the wrong length to be an IMEI\.
114
115# <a name='section4'></a>Bugs, Ideas, Feedback
116
117This document, and the package it describes, will undoubtedly contain bugs and
118other problems\. Please report such in the category *valtype* of the [Tcllib
119Trackers](http://core\.tcl\.tk/tcllib/reportlist)\. Please also report any ideas
120for enhancements you may have for either package and/or documentation\.
121
122When proposing code changes, please provide *unified diffs*, i\.e the output of
123__diff \-u__\.
124
125Note further that *attachments* are strongly preferred over inlined patches\.
126Attachments can be made by going to the __Edit__ form of the ticket
127immediately after its creation, and then using the left\-most button in the
128secondary navigation bar\.
129
130# <a name='keywords'></a>KEYWORDS
131
132[Checking](\.\./\.\./\.\./\.\./index\.md\#checking),
133[IMEI](\.\./\.\./\.\./\.\./index\.md\#imei), [International Mobile Equipment
134Identity](\.\./\.\./\.\./\.\./index\.md\#international\_mobile\_equipment\_identity),
135[Testing](\.\./\.\./\.\./\.\./index\.md\#testing), [Type
136checking](\.\./\.\./\.\./\.\./index\.md\#type\_checking),
137[Validation](\.\./\.\./\.\./\.\./index\.md\#validation), [Value
138checking](\.\./\.\./\.\./\.\./index\.md\#value\_checking),
139[cell\-phone](\.\./\.\./\.\./\.\./index\.md\#cell\_phone),
140[isA](\.\./\.\./\.\./\.\./index\.md\#isa), [mobile
141phone](\.\./\.\./\.\./\.\./index\.md\#mobile\_phone),
142[phone](\.\./\.\./\.\./\.\./index\.md\#phone)
143
144# <a name='category'></a>CATEGORY
145
146Validation, Type checking
147
148# <a name='copyright'></a>COPYRIGHT
149
150Copyright &copy; 2011 Andreas Kupries <andreas\_kupries@users\.sourceforge\.net>
151