Zend_Validate-Barcode.xml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  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. Therefor <classname>Zend_Validate_Barcode</classname> supports multiple barcode standards
  11. and can be extended with proprietary barcode implementations very easily. Actually the
  12. following barcode standards are supported:
  13. </para>
  14. <itemizedlist>
  15. <listitem>
  16. <para>
  17. <emphasis>CODE39</emphasis>: CODE39 is one of the oldest available codes.
  18. </para>
  19. <para>
  20. This barcode has a variable length. It supports digits, alphabetical characters
  21. and 6 special characters. It can have an optional checksum which is calculated with
  22. modulo 43. This standard is used worldwide and common within the industry.
  23. </para>
  24. </listitem>
  25. <listitem>
  26. <para>
  27. <emphasis>EAN8</emphasis>: EAN is the shortcut for "European Article Number".
  28. </para>
  29. <para>
  30. These barcodes must have a length of 8 characters. It supports only digits and
  31. the last digit is always a checksum. This standard is used worldwide but has avery
  32. limited range. It can be found on small atricles where a longer barcode could not
  33. be printed on.
  34. </para>
  35. </listitem>
  36. <listitem>
  37. <para>
  38. <emphasis>EAN12</emphasis>: EAN is the shortcut for "European Article Number".
  39. </para>
  40. <para>
  41. This barcode must have a length of 12 characters. It supports only digits and
  42. the last digit is always a checksum which is calculated with modulo 10. This
  43. standard is used within USA and common on the market. It has been superseeded by
  44. Ean13.
  45. </para>
  46. </listitem>
  47. <listitem>
  48. <para>
  49. <emphasis>EAN13</emphasis>: EAN is the shortcut for "European Article Number".
  50. </para>
  51. <para>
  52. This barcode must have a length of 13 characters. It supports only digits and
  53. the last digit is always a checksum which is calculated with modulo 10. This
  54. standard is used worldwide and common on the market.
  55. </para>
  56. </listitem>
  57. <listitem>
  58. <para>
  59. <emphasis>EAN14</emphasis>: EAN is the shortcut for "European Article Number".
  60. </para>
  61. <para>
  62. This barcode must have a length of 14 characters. It supports only digits and
  63. the last digit is always a checksum which is calculated with modulo 10. This
  64. standard is used worldwide and common on the market. It is the successor for
  65. Ean13.
  66. </para>
  67. </listitem>
  68. <listitem>
  69. <para>
  70. <emphasis>GTIN12</emphasis>: GTIN is the shortcut for "Global Trade Item Number".
  71. </para>
  72. <para>
  73. This barcode uses the same standard as Ean12 and is it's successor. It's commonly
  74. used within USA.
  75. </para>
  76. </listitem>
  77. <listitem>
  78. <para>
  79. <emphasis>GTIN13</emphasis>: GTIN is the shortcut for "Global Trade Item Number".
  80. </para>
  81. <para>
  82. This barcode uses the same standard as Ean13 and is it's successor. It's is used
  83. worldwide by industry.
  84. </para>
  85. </listitem>
  86. <listitem>
  87. <para>
  88. <emphasis>GTIN14</emphasis>: GTIN is the shortcut for "Global Trade Item Number".
  89. </para>
  90. <para>
  91. This barcode uses the same standard as Ean14 and is it's successor. It is used
  92. worldwide and common on the market.
  93. </para>
  94. </listitem>
  95. <listitem>
  96. <para>
  97. <emphasis>INTERLEAVED25</emphasis>: Often called Interleaved two of five.
  98. </para>
  99. <para>
  100. This barcode has no length limitation, but it must contain an even amount of
  101. characters. It supports only digits and the last digit can be an optional checksum
  102. which is calculated with modulo 10. This standard is used worldwide and common on
  103. the market.
  104. </para>
  105. </listitem>
  106. <listitem>
  107. <para>
  108. <emphasis>ITF14</emphasis>: ITF is the shortcut for "Interleaved Two of Five".
  109. </para>
  110. <para>
  111. This barcode is a special variant of Interleaved 2 of 5. It must have a length of
  112. 14 characters and is based on Gtin14. It supports only digits and the last digit
  113. must be a checksum digit which is calculated with modulo 10. It is used worldwide
  114. and common within the market.
  115. </para>
  116. </listitem>
  117. <listitem>
  118. <para>
  119. <emphasis>SSCC</emphasis>: SSCC is the shortcut for "Serial Shipping Container
  120. Code".
  121. </para>
  122. <para>
  123. This barcode is a variant of EAN barcode. It must have a length of 18
  124. characters and supports only digits. The last digit must be a checksum digit
  125. which is calculated with modulo 10. It is commonly used by transport industry.
  126. </para>
  127. </listitem>
  128. <listitem>
  129. <para>
  130. <emphasis>UPCA</emphasis>: UPC is the shortcut for "Univeral Product Code".
  131. </para>
  132. <para>
  133. This barcode preceeded EAN13. It must have a length of 12 characters and supports
  134. only digits. The last digit must be a checksum digit which is calculated with
  135. modulo 10. It is commonly used within USA.
  136. </para>
  137. </listitem>
  138. </itemizedlist>
  139. <sect3 id="zend.validate.set.barcode.basic">
  140. <title>Basic usage</title>
  141. <para>
  142. To validate if a given string is a barcode you just need to know it's type.
  143. See the following example for an EAN13 barcode:
  144. </para>
  145. <programlisting language="php"><![CDATA[
  146. $valid = new Zend_Validate_Barcode('EAN13');
  147. if ($valid->isValid($input)) {
  148. // input appears to be valid
  149. } else {
  150. // input is invalid
  151. }
  152. ]]></programlisting>
  153. </sect3>
  154. <sect3 id="zend.validate.set.barcode.checksum">
  155. <title>Optional checksum</title>
  156. <para>
  157. Some barcodes can be provided with an optional checksum. These barcodes would be
  158. valid even without checksum. Still, when you provide a checksum, then you should
  159. also validate it. These barcode types do per default no checksum validation. By
  160. using the <property>checksum</property> option you can define if the checksum
  161. will be validated or ignored.
  162. </para>
  163. <programlisting language="php"><![CDATA[
  164. $valid = new Zend_Validate_Barcode('adapter' => 'EAN13', 'checksum' => true);
  165. if ($valid->isValid($input)) {
  166. // input appears to be valid
  167. } else {
  168. // input is invalid
  169. }
  170. ]]></programlisting>
  171. <note>
  172. <title>Reduced security by disabling checksum validation</title>
  173. <para>
  174. By switching off checksum validation you will also reduce the security of the
  175. used barcodes. Additionally you should note that you can also turn off the
  176. checksum validation for these barcode types which must contain a checksum
  177. value. Barcodes which would not be valid could then be returned as valid even
  178. if they are not.
  179. </para>
  180. </note>
  181. </sect3>
  182. <sect3 id="zend.validate.set.barcode.selfwritten">
  183. <title>Self written adapters</title>
  184. <para>
  185. Of course it's possible to write barcode validators yourself. This could be
  186. necessary as many barcode types are properitary. To write your own barcode
  187. validator you need some informations.
  188. </para>
  189. <itemizedlist>
  190. <listitem>
  191. <para>
  192. <emphasis>Length</emphasis>: The length your barcode must have. It can have one
  193. of the following values:
  194. </para>
  195. <itemizedlist>
  196. <listitem>
  197. <para>
  198. <emphasis>Integer</emphasis>: A value greater 0, which means that the
  199. barcode must have this length.
  200. </para>
  201. </listitem>
  202. <listitem>
  203. <para>
  204. <emphasis>-1</emphasis>: There is no limitation for the length of this
  205. barcode.
  206. </para>
  207. </listitem>
  208. <listitem>
  209. <para>
  210. <emphasis>'even'</emphasis>: The length of this barcode must have a
  211. even amount of digits.
  212. </para>
  213. </listitem>
  214. <listitem>
  215. <para>
  216. <emphasis>'odd'</emphasis>: The length of this barcode must have a
  217. odd amount of digits.
  218. </para>
  219. </listitem>
  220. <listitem>
  221. <para>
  222. <emphasis>array</emphasis>: An array of integer values. The length of
  223. this barcode must have one of the set array values.
  224. </para>
  225. </listitem>
  226. </itemizedlist>
  227. </listitem>
  228. <listitem>
  229. <para>
  230. <emphasis>Characters</emphasis>: A string which contains all allowed characters
  231. for this barcode. Also the integer value 128 is allowed, which means the first
  232. 128 characters of the ASCII table.
  233. </para>
  234. </listitem>
  235. <listitem>
  236. <para>
  237. <emphasis>Checksum</emphasis>: A string which will be used as callback for a
  238. method which does the checksum validation.
  239. </para>
  240. </listitem>
  241. </itemizedlist>
  242. <para>
  243. Additionally your own barcode validator must extend
  244. <classname>BarcodeAdapter</classname>.
  245. </para>
  246. <para>
  247. Now let's concat all options together and write a own barcode validator. Let's expect
  248. that our barcode must be even, it can have all digits and additionally the chars
  249. 'ABCDE', and it has a checksum.
  250. </para>
  251. <programlisting language="php"><![CDATA[
  252. class My_Barcode_MyBar extends Zend_Validate_Barcode_BarcodeAdapter
  253. {
  254. protected $_length = 'even';
  255. protected $_characters = '0123456789ABCDE';
  256. protected $_checksum = '_mod66';
  257. protected function _mod66($barcode)
  258. {
  259. // do some validations and return a boolean
  260. }
  261. }
  262. $valid = new Zend_Validate_Barcode('My_Barcode_MyBar');
  263. if ($valid->isValid($input)) {
  264. // input appears to be valid
  265. } else {
  266. // input is invalid
  267. }
  268. ]]></programlisting>
  269. </sect3>
  270. </sect2>
  271. <!--
  272. vim:se ts=4 sw=4 et:
  273. -->