Zend_Validate-Barcode.xml 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <sect2 id="zend.validate.set.barcode">
  4. <title>Barcode</title>
  5. <para>
  6. <classname>Zend_Validate_Barcode</classname> allows you to check if a given value can be
  7. represented as barcode.
  8. </para>
  9. <para>
  10. <classname>Zend_Validate_Barcode</classname> supports multiple barcode standards and can be
  11. extended with proprietary barcode implementations very easily. The following barcode
  12. standards are supported:
  13. </para>
  14. <itemizedlist>
  15. <listitem>
  16. <para>
  17. <emphasis>CODE25</emphasis>: Often called "two of five" or "Code25 Industrial".
  18. </para>
  19. <para>
  20. This barcode has no length limitation. It supports only digits, and the last digit
  21. can be an optional checksum which is calculated with modulo 10. This standard is
  22. very old and nowadays not often used. Common usecases are within the industry.
  23. </para>
  24. </listitem>
  25. <listitem>
  26. <para>
  27. <emphasis>CODE25INTERLEAVED</emphasis>: Often called "Code 2 of 5 Interleaved".
  28. </para>
  29. <para>
  30. This standard is a variant of CODE25. It has no length limitation, but it must
  31. contain an even amount of characters. It supports only digits, and the last digit
  32. can be an optional checksum which is calculated with modulo 10. It is used worldwide
  33. and common on the market.
  34. </para>
  35. </listitem>
  36. <listitem>
  37. <para>
  38. <emphasis>CODE39</emphasis>: CODE39 is one of the oldest available codes.
  39. </para>
  40. <para>
  41. This barcode has a variable length. It supports digits, upper cased alphabetical
  42. characters and 7 special characters like whitespace, point and dollar sign. It can
  43. have an optional checksum which is calculated with modulo 43. This standard is used
  44. worldwide and common within the industry.
  45. </para>
  46. </listitem>
  47. <listitem>
  48. <para>
  49. <emphasis>CODE39EXT</emphasis>: CODE39EXT is an extension of CODE39.
  50. </para>
  51. <para>
  52. This barcode has the same properties as CODE39. Additionally it allows the usage of
  53. all 128 ASCII characters. This standard is used worldwide and common within the
  54. industry.
  55. </para>
  56. </listitem>
  57. <listitem>
  58. <para>
  59. <emphasis>CODE93</emphasis>: CODE93 is the successor of CODE39.
  60. </para>
  61. <para>
  62. This barcode has a variable length. It supports digits, alphabetical characters
  63. and 7 special characters. It has an checksum which is calculated with modulo 47 and
  64. contains 2 characters. This standard produces a denser code than CODE39 and is more
  65. secure.
  66. </para>
  67. </listitem>
  68. <listitem>
  69. <para>
  70. <emphasis>EAN8</emphasis>: EAN is the shortcut for "European Article Number".
  71. </para>
  72. <para>
  73. These barcodes must have a length of 8 characters. It supports only digits, and
  74. the last digit is always a checksum. This standard is used worldwide but has a very
  75. limited range. It can be found on small articles where a longer barcode could not
  76. be printed.
  77. </para>
  78. </listitem>
  79. <listitem>
  80. <para>
  81. <emphasis>EAN12</emphasis>: EAN is the shortcut for "European Article Number".
  82. </para>
  83. <para>
  84. This barcode must have a length of 12 characters. It supports only digits, and the
  85. last digit is always a checksum which is calculated with modulo 10. This standard is
  86. used within the USA and common on the market. It has been superceded by EAN13.
  87. </para>
  88. </listitem>
  89. <listitem>
  90. <para>
  91. <emphasis>EAN13</emphasis>: EAN is the shortcut for "European Article Number".
  92. </para>
  93. <para>
  94. This barcode must have a length of 13 characters. It supports only digits, and the
  95. last digit is always a checksum which is calculated with modulo 10. This standard is
  96. used worldwide and common on the market.
  97. </para>
  98. </listitem>
  99. <listitem>
  100. <para>
  101. <emphasis>EAN14</emphasis>: EAN is the shortcut for "European Article Number".
  102. </para>
  103. <para>
  104. This barcode must have a length of 14 characters. It supports only digits, and the
  105. last digit is always a checksum which is calculated with modulo 10. This standard is
  106. used worldwide and common on the market. It is the successor for EAN13.
  107. </para>
  108. </listitem>
  109. <listitem>
  110. <para>
  111. <emphasis>EAN18</emphasis>: EAN is the shortcut for "European Article Number".
  112. </para>
  113. <para>
  114. This barcode must have a length of 18 characters. It support only digits. The last
  115. digit is always a checksum digit which is calculated with modulo 10. This code is often
  116. used for the identification of shipping containers.
  117. </para>
  118. </listitem>
  119. <listitem>
  120. <para>
  121. <emphasis>GTIN12</emphasis>: GTIN is the shortcut for "Global Trade Item Number".
  122. </para>
  123. <para>
  124. This barcode uses the same standard as EAN12 and is its successor. It's commonly
  125. used within the USA.
  126. </para>
  127. </listitem>
  128. <listitem>
  129. <para>
  130. <emphasis>GTIN13</emphasis>: GTIN is the shortcut for "Global Trade Item Number".
  131. </para>
  132. <para>
  133. This barcode uses the same standard as EAN13 and is its successor. It is used
  134. worldwide by industry.
  135. </para>
  136. </listitem>
  137. <listitem>
  138. <para>
  139. <emphasis>GTIN14</emphasis>: GTIN is the shortcut for "Global Trade Item Number".
  140. </para>
  141. <para>
  142. This barcode uses the same standard as EAN14 and is its successor. It is used
  143. worldwide and common on the market.
  144. </para>
  145. </listitem>
  146. <listitem>
  147. <para>
  148. <emphasis>IDENTCODE</emphasis>: Identcode is used by Deutsche Post and DHL. It's an
  149. specialized implementation of Code25.
  150. </para>
  151. <para>
  152. This barcode must have a length of 12 characters. It supports only digits, and the
  153. last digit is always a checksum which is calculated with modulo 10. This standard is
  154. mainly used by the companies DP and DHL.
  155. </para>
  156. </listitem>
  157. <listitem>
  158. <para>
  159. <emphasis>ITF14</emphasis>: ITF14 is the GS1 implementation of an Interleaved Two
  160. of Five bar code.
  161. </para>
  162. <para>
  163. This barcode is a special variant of Interleaved 2 of 5. It must have a length of
  164. 14 characters and is based on GTIN14. It supports only digits, and the last digit
  165. must be a checksum digit which is calculated with modulo 10. It is used worldwide
  166. and common within the market.
  167. </para>
  168. </listitem>
  169. <listitem>
  170. <para>
  171. <emphasis>LEITCODE</emphasis>: Leitcode is used by Deutsche Post and DHL. It's an
  172. specialized implementation of Code25.
  173. </para>
  174. <para>
  175. This barcode must have a length of 14 characters. It supports only digits, and the
  176. last digit is always a checksum which is calculated with modulo 10. This standard is
  177. mainly used by the companies DP and DHL.
  178. </para>
  179. </listitem>
  180. <listitem>
  181. <para>
  182. <emphasis>SSCC</emphasis>: SSCC is the shortcut for "Serial Shipping Container
  183. Code".
  184. </para>
  185. <para>
  186. This barcode is a variant of EAN barcode. It must have a length of 18 characters and
  187. supports only digits. The last digit must be a checksum digit which is calculated
  188. with modulo 10. It is commonly used by the transport industry.
  189. </para>
  190. </listitem>
  191. <listitem>
  192. <para>
  193. <emphasis>UPCA</emphasis>: UPC is the shortcut for "Univeral Product Code".
  194. </para>
  195. <para>
  196. This barcode preceeded EAN13. It must have a length of 12 characters and supports
  197. only digits. The last digit must be a checksum digit which is calculated with
  198. modulo 10. It is commonly used within the USA.
  199. </para>
  200. </listitem>
  201. <listitem>
  202. <para>
  203. <emphasis>UPCE</emphasis>: UPCE is the short variant from UPCA.
  204. </para>
  205. <para>
  206. This barcode is a smaller variant of UPCA. It can have a length of 6, 7 or 8
  207. characters and supports only digits. When the barcode is 8 chars long it includes
  208. a checksum which is calculated with modulo 10. It is commonly used with small
  209. products where a UPCA barcode would not fit.
  210. </para>
  211. </listitem>
  212. </itemizedlist>
  213. <sect3 id="zend.validate.set.barcode.basic">
  214. <title>Basic usage</title>
  215. <para>
  216. To validate if a given string is a barcode you just need to know its type. See the
  217. following example for an EAN13 barcode:
  218. </para>
  219. <programlisting language="php"><![CDATA[
  220. $valid = new Zend_Validate_Barcode('EAN13');
  221. if ($valid->isValid($input)) {
  222. // input appears to be valid
  223. } else {
  224. // input is invalid
  225. }
  226. ]]></programlisting>
  227. </sect3>
  228. <sect3 id="zend.validate.set.barcode.checksum">
  229. <title>Optional checksum</title>
  230. <para>
  231. Some barcodes can be provided with an optional checksum. These barcodes would be valid
  232. even without checksum. Still, when you provide a checksum, then you should also validate
  233. it. By default, these barcode types perform no checksum validation. By using the
  234. <property>checksum</property> option you can define if the checksum will be validated or
  235. ignored.
  236. </para>
  237. <programlisting language="php"><![CDATA[
  238. $valid = new Zend_Validate_Barcode(array(
  239. 'adapter' => 'EAN13',
  240. 'checksum' => false,
  241. ));
  242. if ($valid->isValid($input)) {
  243. // input appears to be valid
  244. } else {
  245. // input is invalid
  246. }
  247. ]]></programlisting>
  248. <note>
  249. <title>Reduced security by disabling checksum validation</title>
  250. <para>
  251. By switching off checksum validation you will also reduce the security of the used
  252. barcodes. Additionally you should note that you can also turn off the checksum
  253. validation for those barcode types which must contain a checksum value. Barcodes
  254. which would not be valid could then be returned as valid even if they are not.
  255. </para>
  256. </note>
  257. </sect3>
  258. <sect3 id="zend.validate.set.barcode.custom">
  259. <title>Writing custom adapters</title>
  260. <para>
  261. You may write custom barcode validators for usage with
  262. <classname>Zend_Validate_Barcode</classname>; this is often necessary when dealing with
  263. proprietary barcode types. To write your own barcode validator, you need the following
  264. information.
  265. </para>
  266. <itemizedlist>
  267. <listitem>
  268. <para>
  269. <emphasis>Length</emphasis>: The length your barcode must have. It can have one
  270. of the following values:
  271. </para>
  272. <itemizedlist>
  273. <listitem>
  274. <para>
  275. <emphasis>Integer</emphasis>: A value greater 0, which means that the
  276. barcode must have this length.
  277. </para>
  278. </listitem>
  279. <listitem>
  280. <para>
  281. <emphasis>-1</emphasis>: There is no limitation for the length of this
  282. barcode.
  283. </para>
  284. </listitem>
  285. <listitem>
  286. <para>
  287. <emphasis>"even"</emphasis>: The length of this barcode must have a
  288. even amount of digits.
  289. </para>
  290. </listitem>
  291. <listitem>
  292. <para>
  293. <emphasis>"odd"</emphasis>: The length of this barcode must have a
  294. odd amount of digits.
  295. </para>
  296. </listitem>
  297. <listitem>
  298. <para>
  299. <emphasis>array</emphasis>: An array of integer values. The length of
  300. this barcode must have one of the set array values.
  301. </para>
  302. </listitem>
  303. </itemizedlist>
  304. </listitem>
  305. <listitem>
  306. <para>
  307. <emphasis>Characters</emphasis>: A string which contains all allowed characters
  308. for this barcode. Also the integer value 128 is allowed, which means the first
  309. 128 characters of the ASCII table.
  310. </para>
  311. </listitem>
  312. <listitem>
  313. <para>
  314. <emphasis>Checksum</emphasis>: A string which will be used as callback for a
  315. method which does the checksum validation.
  316. </para>
  317. </listitem>
  318. </itemizedlist>
  319. <para>
  320. Your custom barcode validator must extend
  321. <classname>Zend_Validate_Barcode_AdapterAbstract</classname> or implement
  322. <interface>Zend_Validate_Barcode_AdapterInterface</interface>.
  323. </para>
  324. <para>
  325. As an example, let's create a validator that expects an even number of characters that
  326. include all digits and the letters 'ABCDE', and which requires a checksum.
  327. </para>
  328. <programlisting language="php"><![CDATA[
  329. class My_Barcode_MyBar extends Zend_Validate_Barcode_AdapterAbstract
  330. {
  331. protected $_length = 'even';
  332. protected $_characters = '0123456789ABCDE';
  333. protected $_checksum = '_mod66';
  334. protected function _mod66($barcode)
  335. {
  336. // do some validations and return a boolean
  337. }
  338. }
  339. $valid = new Zend_Validate_Barcode('My_Barcode_MyBar');
  340. if ($valid->isValid($input)) {
  341. // input appears to be valid
  342. } else {
  343. // input is invalid
  344. }
  345. ]]></programlisting>
  346. </sect3>
  347. </sect2>
  348. <!--
  349. vim:se ts=4 sw=4 et:
  350. -->