Zend_Validate-Barcode.xml 13 KB

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