Zend_Validate-Barcode.xml 14 KB

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