1 <?xml version="1.0" encoding="UTF-8"?>
3 <sect2 id="zend.validate.set.barcode">
7 <classname>Zend_Validate_Barcode</classname> allows you to check if a given value can be
8 represented as barcode.
12 <classname>Zend_Validate_Barcode</classname> supports multiple barcode standards and can be
13 extended with proprietary barcode implementations very easily. The following barcode
14 standards are supported:
20 <emphasis>CODE25</emphasis>: Often called "two of five" or "Code25 Industrial".
24 This barcode has no length limitation. It supports only digits, and the last digit
25 can be an optional checksum which is calculated with modulo 10. This standard is
26 very old and nowadays not often used. Common usecases are within the industry.
32 <emphasis>CODE25INTERLEAVED</emphasis>: Often called "Code 2 of 5 Interleaved".
36 This standard is a variant of CODE25. It has no length limitation, but it must
37 contain an even amount of characters. It supports only digits, and the last digit
38 can be an optional checksum which is calculated with modulo 10. It is used worldwide
39 and common on the market.
45 <emphasis>CODE39</emphasis>: CODE39 is one of the oldest available codes.
49 This barcode has a variable length. It supports digits, upper cased alphabetical
50 characters and 7 special characters like whitespace, point and dollar sign. It can
51 have an optional checksum which is calculated with modulo 43. This standard is used
52 worldwide and common within the industry.
58 <emphasis>CODE39EXT</emphasis>: CODE39EXT is an extension of CODE39.
62 This barcode has the same properties as CODE39. Additionally it allows the usage of
63 all 128 ASCII characters. This standard is used worldwide and common within the
70 <emphasis>CODE93</emphasis>: CODE93 is the successor of CODE39.
74 This barcode has a variable length. It supports digits, alphabetical characters
75 and 7 special characters. It has an optional checksum which is calculated with
76 modulo 47 and contains 2 characters. This standard produces a denser code than
77 CODE39 and is more secure.
83 <emphasis>CODE93EXT</emphasis>: CODE93EXT is an extension of CODE93.
87 This barcode has the same properties as CODE93. Additionally it allows the usage of
88 all 128 ASCII characters. This standard is used worldwide and common within the
95 <emphasis>EAN2</emphasis>: EAN is the shortcut for "European Article Number".
99 These barcode must have 2 characters. It supports only digits and does not have a
100 checksum. This standard is mainly used as addition to EAN13 (ISBN) when printed on
107 <emphasis>EAN5</emphasis>: EAN is the shortcut for "European Article Number".
111 These barcode must have 5 characters. It supports only digits and does not have a
112 checksum. This standard is mainly used as addition to EAN13 (ISBN) when printed on
119 <emphasis>EAN8</emphasis>: EAN is the shortcut for "European Article Number".
123 These barcode can have 7 or 8 characters. It supports only digits. When it has a
124 length of 8 characters it includes a checksum. This standard is used worldwide but
125 has a very limited range. It can be found on small articles where a longer barcode
126 could not be printed.
132 <emphasis>EAN12</emphasis>: EAN is the shortcut for "European Article Number".
136 This barcode must have a length of 12 characters. It supports only digits, and the
137 last digit is always a checksum which is calculated with modulo 10. This standard is
138 used within the USA and common on the market. It has been superceded by EAN13.
144 <emphasis>EAN13</emphasis>: EAN is the shortcut for "European Article Number".
148 This barcode must have a length of 13 characters. It supports only digits, and the
149 last digit is always a checksum which is calculated with modulo 10. This standard is
150 used worldwide and common on the market.
156 <emphasis>EAN14</emphasis>: EAN is the shortcut for "European Article Number".
160 This barcode must have a length of 14 characters. It supports only digits, and the
161 last digit is always a checksum which is calculated with modulo 10. This standard is
162 used worldwide and common on the market. It is the successor for EAN13.
168 <emphasis>EAN18</emphasis>: EAN is the shortcut for "European Article Number".
172 This barcode must have a length of 18 characters. It support only digits. The last
173 digit is always a checksum digit which is calculated with modulo 10. This code is
174 often used for the identification of shipping containers.
180 <emphasis>GTIN12</emphasis>: GTIN is the shortcut for "Global Trade Item Number".
184 This barcode uses the same standard as EAN12 and is its successor. It's commonly
191 <emphasis>GTIN13</emphasis>: GTIN is the shortcut for "Global Trade Item Number".
195 This barcode uses the same standard as EAN13 and is its successor. It is used
196 worldwide by industry.
202 <emphasis>GTIN14</emphasis>: GTIN is the shortcut for "Global Trade Item Number".
206 This barcode uses the same standard as EAN14 and is its successor. It is used
207 worldwide and common on the market.
213 <emphasis>IDENTCODE</emphasis>: Identcode is used by Deutsche Post and DHL. It's an
214 specialized implementation of Code25.
218 This barcode must have a length of 12 characters. It supports only digits, and the
219 last digit is always a checksum which is calculated with modulo 10. This standard is
220 mainly used by the companies DP and DHL.
226 <emphasis>INTELLIGENTMAIL</emphasis>: Intelligent Mail is a postal barcode.
230 This barcode can have a length of 20, 25, 29 or 31 characters. It supports only
231 digits, and contains no checksum. This standard is the successor of
232 <acronym>PLANET</acronym> and <acronym>POSTNET</acronym>. It is mainly used by the
233 United States Postal Services.
239 <emphasis>ISSN</emphasis>: <acronym>ISSN</acronym> is the abbreviation for
240 International Standard Serial Number.
244 This barcode can have a length of 8 or 13 characters. It supports only digits,
245 and the last digit must be a checksum digit which is calculated with modulo 11.
246 It is used worldwide for printed publications.
252 <emphasis>ITF14</emphasis>: ITF14 is the GS1 implementation of an Interleaved Two
257 This barcode is a special variant of Interleaved 2 of 5. It must have a length of
258 14 characters and is based on GTIN14. It supports only digits, and the last digit
259 must be a checksum digit which is calculated with modulo 10. It is used worldwide
260 and common within the market.
266 <emphasis>LEITCODE</emphasis>: Leitcode is used by Deutsche Post and DHL. It's an
267 specialized implementation of Code25.
271 This barcode must have a length of 14 characters. It supports only digits, and the
272 last digit is always a checksum which is calculated with modulo 10. This standard is
273 mainly used by the companies DP and DHL.
279 <emphasis>PLANET</emphasis>: Planet is the abbreviation for Postal Alpha Numeric
284 This barcode can have a length of 12 or 14 characters. It supports only digits, and
285 the last digit is always a checksum. This standard is mainly used by the United
286 States Postal Services.
292 <emphasis>POSTNET</emphasis>: Postnet is used by the US Postal Service.
296 This barcode can have a length of 6, 7, 10 or 12 characters. It supports only
297 digits, and the last digit is always a checksum. This standard is mainly used
298 by the United States Postal Services.
304 <emphasis>ROYALMAIL</emphasis>: Royalmail is used by Royal Mail.
308 This barcode has no defined length. It supports digits, uppercased letters, and the
309 last digit is always a checksum. This standard is mainly used by Royal Mail for
310 their Cleanmail Service. It is also called <acronym>RM4SCC</acronym>.
316 <emphasis>SSCC</emphasis>: SSCC is the shortcut for "Serial Shipping Container
321 This barcode is a variant of EAN barcode. It must have a length of 18 characters and
322 supports only digits. The last digit must be a checksum digit which is calculated
323 with modulo 10. It is commonly used by the transport industry.
329 <emphasis>UPCA</emphasis>: UPC is the shortcut for "Univeral Product Code".
333 This barcode preceeded EAN13. It must have a length of 12 characters and supports
334 only digits. The last digit must be a checksum digit which is calculated with
335 modulo 10. It is commonly used within the USA.
341 <emphasis>UPCE</emphasis>: UPCE is the short variant from UPCA.
345 This barcode is a smaller variant of UPCA. It can have a length of 6, 7 or 8
346 characters and supports only digits. When the barcode is 8 chars long it includes
347 a checksum which is calculated with modulo 10. It is commonly used with small
348 products where a UPCA barcode would not fit.
353 <sect3 id="zend.validate.set.barcode.options">
354 <title>Supported options for Zend_Validate_Barcode</title>
357 The following options are supported for <classname>Zend_Validate_Barcode</classname>:
363 <emphasis><property>adapter</property></emphasis>: Sets the barcode adapter
364 which will be used. Supported are all above noted adapters. When using a self
365 defined adapter, then you have to set the complete classname.
371 <emphasis><property>checksum</property></emphasis>: <constant>TRUE</constant>
372 when the barcode should contain a checksum. The default value depends on the
373 used adapter. Note that some adapters don't allow to set this option.
379 <emphasis><property>options</property></emphasis>: Defines optional options for
380 a self written adapters.
386 <sect3 id="zend.validate.set.barcode.basic">
387 <title>Basic usage</title>
390 To validate if a given string is a barcode you just need to know its type. See the
391 following example for an EAN13 barcode:
394 <programlisting language="php"><![CDATA[
395 $valid = new Zend_Validate_Barcode('EAN13');
396 if ($valid->isValid($input)) {
397 // input appears to be valid
404 <sect3 id="zend.validate.set.barcode.checksum">
405 <title>Optional checksum</title>
408 Some barcodes can be provided with an optional checksum. These barcodes would be valid
409 even without checksum. Still, when you provide a checksum, then you should also validate
410 it. By default, these barcode types perform no checksum validation. By using the
411 <property>checksum</property> option you can define if the checksum will be validated or
415 <programlisting language="php"><![CDATA[
416 $valid = new Zend_Validate_Barcode(array(
417 'adapter' => 'EAN13',
420 if ($valid->isValid($input)) {
421 // input appears to be valid
428 <title>Reduced security by disabling checksum validation</title>
431 By switching off checksum validation you will also reduce the security of the used
432 barcodes. Additionally you should note that you can also turn off the checksum
433 validation for those barcode types which must contain a checksum value. Barcodes
434 which would not be valid could then be returned as valid even if they are not.
439 <sect3 id="zend.validate.set.barcode.custom">
440 <title>Writing custom adapters</title>
443 You may write custom barcode validators for usage with
444 <classname>Zend_Validate_Barcode</classname>; this is often necessary when dealing with
445 proprietary barcode types. To write your own barcode validator, you need the following
452 <emphasis>Length</emphasis>: The length your barcode must have. It can have one
453 of the following values:
459 <emphasis>Integer</emphasis>: A value greater 0, which means that the
460 barcode must have this length.
466 <emphasis>-1</emphasis>: There is no limitation for the length of this
473 <emphasis>"even"</emphasis>: The length of this barcode must have a
474 even amount of digits.
480 <emphasis>"odd"</emphasis>: The length of this barcode must have a
481 odd amount of digits.
487 <emphasis>array</emphasis>: An array of integer values. The length of
488 this barcode must have one of the set array values.
496 <emphasis>Characters</emphasis>: A string which contains all allowed characters
497 for this barcode. Also the integer value 128 is allowed, which means the first
498 128 characters of the ASCII table.
504 <emphasis>Checksum</emphasis>: A string which will be used as callback for a
505 method which does the checksum validation.
511 Your custom barcode validator must extend
512 <classname>Zend_Validate_Barcode_AdapterAbstract</classname> or implement
513 <interface>Zend_Validate_Barcode_AdapterInterface</interface>.
517 As an example, let's create a validator that expects an even number of characters that
518 include all digits and the letters 'ABCDE', and which requires a checksum.
521 <programlisting language="php"><![CDATA[
522 class My_Barcode_MyBar extends Zend_Validate_Barcode_AdapterAbstract
524 protected $_length = 'even';
525 protected $_characters = '0123456789ABCDE';
526 protected $_checksum = '_mod66';
528 protected function _mod66($barcode)
530 // do some validations and return a boolean
534 $valid = new Zend_Validate_Barcode('My_Barcode_MyBar');
535 if ($valid->isValid($input)) {
536 // input appears to be valid