Zend_Validate-Barcode.xml 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545
  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 optional checksum which is calculated with
  64. modulo 47 and contains 2 characters. This standard produces a denser code than
  65. CODE39 and is more secure.
  66. </para>
  67. </listitem>
  68. <listitem>
  69. <para>
  70. <emphasis>CODE93EXT</emphasis>: CODE93EXT is an extension of CODE93.
  71. </para>
  72. <para>
  73. This barcode has the same properties as CODE93. Additionally it allows the usage of
  74. all 128 ASCII characters. This standard is used worldwide and common within the
  75. industry.
  76. </para>
  77. </listitem>
  78. <listitem>
  79. <para>
  80. <emphasis>EAN2</emphasis>: EAN is the shortcut for "European Article Number".
  81. </para>
  82. <para>
  83. These barcode must have 2 characters. It supports only digits and does not have a
  84. checksum. This standard is mainly used as addition to EAN13 (ISBN) when printed on
  85. books.
  86. </para>
  87. </listitem>
  88. <listitem>
  89. <para>
  90. <emphasis>EAN5</emphasis>: EAN is the shortcut for "European Article Number".
  91. </para>
  92. <para>
  93. These barcode must have 5 characters. It supports only digits and does not have a
  94. checksum. This standard is mainly used as addition to EAN13 (ISBN) when printed on
  95. books.
  96. </para>
  97. </listitem>
  98. <listitem>
  99. <para>
  100. <emphasis>EAN8</emphasis>: EAN is the shortcut for "European Article Number".
  101. </para>
  102. <para>
  103. These barcode can have 7 or 8 characters. It supports only digits. When it has a
  104. length of 8 characters it includes a checksum. This standard is used worldwide but
  105. has a very limited range. It can be found on small articles where a longer barcode
  106. could not be printed.
  107. </para>
  108. </listitem>
  109. <listitem>
  110. <para>
  111. <emphasis>EAN12</emphasis>: EAN is the shortcut for "European Article Number".
  112. </para>
  113. <para>
  114. This barcode must have a length of 12 characters. It supports only digits, and the
  115. last digit is always a checksum which is calculated with modulo 10. This standard is
  116. used within the USA and common on the market. It has been superceded by EAN13.
  117. </para>
  118. </listitem>
  119. <listitem>
  120. <para>
  121. <emphasis>EAN13</emphasis>: EAN is the shortcut for "European Article Number".
  122. </para>
  123. <para>
  124. This barcode must have a length of 13 characters. It supports only digits, and the
  125. last digit is always a checksum which is calculated with modulo 10. This standard is
  126. used worldwide and common on the market.
  127. </para>
  128. </listitem>
  129. <listitem>
  130. <para>
  131. <emphasis>EAN14</emphasis>: EAN is the shortcut for "European Article Number".
  132. </para>
  133. <para>
  134. This barcode must have a length of 14 characters. It supports only digits, and the
  135. last digit is always a checksum which is calculated with modulo 10. This standard is
  136. used worldwide and common on the market. It is the successor for EAN13.
  137. </para>
  138. </listitem>
  139. <listitem>
  140. <para>
  141. <emphasis>EAN18</emphasis>: EAN is the shortcut for "European Article Number".
  142. </para>
  143. <para>
  144. This barcode must have a length of 18 characters. It support only digits. The last
  145. digit is always a checksum digit which is calculated with modulo 10. This code is
  146. often used for the identification of shipping containers.
  147. </para>
  148. </listitem>
  149. <listitem>
  150. <para>
  151. <emphasis>GTIN12</emphasis>: GTIN is the shortcut for "Global Trade Item Number".
  152. </para>
  153. <para>
  154. This barcode uses the same standard as EAN12 and is its successor. It's commonly
  155. used within the USA.
  156. </para>
  157. </listitem>
  158. <listitem>
  159. <para>
  160. <emphasis>GTIN13</emphasis>: GTIN is the shortcut for "Global Trade Item Number".
  161. </para>
  162. <para>
  163. This barcode uses the same standard as EAN13 and is its successor. It is used
  164. worldwide by industry.
  165. </para>
  166. </listitem>
  167. <listitem>
  168. <para>
  169. <emphasis>GTIN14</emphasis>: GTIN is the shortcut for "Global Trade Item Number".
  170. </para>
  171. <para>
  172. This barcode uses the same standard as EAN14 and is its successor. It is used
  173. worldwide and common on the market.
  174. </para>
  175. </listitem>
  176. <listitem>
  177. <para>
  178. <emphasis>IDENTCODE</emphasis>: Identcode is used by Deutsche Post and DHL. It's an
  179. specialized implementation of Code25.
  180. </para>
  181. <para>
  182. This barcode must have a length of 12 characters. It supports only digits, and the
  183. last digit is always a checksum which is calculated with modulo 10. This standard is
  184. mainly used by the companies DP and DHL.
  185. </para>
  186. </listitem>
  187. <listitem>
  188. <para>
  189. <emphasis>INTELLIGENTMAIL</emphasis>: Intelligent Mail is a postal barcode.
  190. </para>
  191. <para>
  192. This barcode can have a length of 20, 25, 29 or 31 characters. It supports only
  193. digits, and contains no checksum. This standard is the successor of
  194. <acronym>PLANET</acronym> and <acronym>POSTNET</acronym>. It is mainly used by the
  195. United States Postal Services.
  196. </para>
  197. </listitem>
  198. <listitem>
  199. <para>
  200. <emphasis>ISSN</emphasis>: <acronym>ISSN</acronym> is the abbreviation for
  201. International Standard Serial Number.
  202. </para>
  203. <para>
  204. This barcode can have a length of 8 or 13 characters. It supports only digits,
  205. and the last digit must be a checksum digit which is calculated with modulo 11.
  206. It is used worldwide for printed publications.
  207. </para>
  208. </listitem>
  209. <listitem>
  210. <para>
  211. <emphasis>ITF14</emphasis>: ITF14 is the GS1 implementation of an Interleaved Two
  212. of Five bar code.
  213. </para>
  214. <para>
  215. This barcode is a special variant of Interleaved 2 of 5. It must have a length of
  216. 14 characters and is based on GTIN14. It supports only digits, and the last digit
  217. must be a checksum digit which is calculated with modulo 10. It is used worldwide
  218. and common within the market.
  219. </para>
  220. </listitem>
  221. <listitem>
  222. <para>
  223. <emphasis>LEITCODE</emphasis>: Leitcode is used by Deutsche Post and DHL. It's an
  224. specialized implementation of Code25.
  225. </para>
  226. <para>
  227. This barcode must have a length of 14 characters. It supports only digits, and the
  228. last digit is always a checksum which is calculated with modulo 10. This standard is
  229. mainly used by the companies DP and DHL.
  230. </para>
  231. </listitem>
  232. <listitem>
  233. <para>
  234. <emphasis>PLANET</emphasis>: Planet is the abbreviation for Postal Alpha Numeric
  235. Encoding Technique.
  236. </para>
  237. <para>
  238. This barcode can have a length of 12 or 14 characters. It supports only digits, and
  239. the last digit is always a checksum. This standard is mainly used by the United
  240. States Postal Services.
  241. </para>
  242. </listitem>
  243. <listitem>
  244. <para>
  245. <emphasis>POSTNET</emphasis>: Postnet is used by the US Postal Service.
  246. </para>
  247. <para>
  248. This barcode can have a length of 6, 7, 10 or 12 characters. It supports only
  249. digits, and the last digit is always a checksum. This standard is mainly used
  250. by the United States Postal Services.
  251. </para>
  252. </listitem>
  253. <listitem>
  254. <para>
  255. <emphasis>ROYALMAIL</emphasis>: Royalmail is used by Royal Mail.
  256. </para>
  257. <para>
  258. This barcode has no defined length. It supports digits, uppercased letters, and the
  259. last digit is always a checksum. This standard is mainly used by Royal Mail for
  260. their Cleanmail Service. It is also called <acronym>RM4SCC</acronym>.
  261. </para>
  262. </listitem>
  263. <listitem>
  264. <para>
  265. <emphasis>SSCC</emphasis>: SSCC is the shortcut for "Serial Shipping Container
  266. Code".
  267. </para>
  268. <para>
  269. This barcode is a variant of EAN barcode. It must have a length of 18 characters and
  270. supports only digits. The last digit must be a checksum digit which is calculated
  271. with modulo 10. It is commonly used by the transport industry.
  272. </para>
  273. </listitem>
  274. <listitem>
  275. <para>
  276. <emphasis>UPCA</emphasis>: UPC is the shortcut for "Univeral Product Code".
  277. </para>
  278. <para>
  279. This barcode preceeded EAN13. It must have a length of 12 characters and supports
  280. only digits. The last digit must be a checksum digit which is calculated with
  281. modulo 10. It is commonly used within the USA.
  282. </para>
  283. </listitem>
  284. <listitem>
  285. <para>
  286. <emphasis>UPCE</emphasis>: UPCE is the short variant from UPCA.
  287. </para>
  288. <para>
  289. This barcode is a smaller variant of UPCA. It can have a length of 6, 7 or 8
  290. characters and supports only digits. When the barcode is 8 chars long it includes
  291. a checksum which is calculated with modulo 10. It is commonly used with small
  292. products where a UPCA barcode would not fit.
  293. </para>
  294. </listitem>
  295. </itemizedlist>
  296. <sect3 id="zend.validate.set.barcode.options">
  297. <title>Supported options for Zend_Validate_Barcode</title>
  298. <para>
  299. The following options are supported for <classname>Zend_Validate_Barcode</classname>:
  300. </para>
  301. <itemizedlist>
  302. <listitem>
  303. <para>
  304. <emphasis><property>adapter</property></emphasis>: Sets the barcode adapter
  305. which will be used. Supported are all above noted adapters. When using a self
  306. defined adapter, then you have to set the complete classname.
  307. </para>
  308. </listitem>
  309. <listitem>
  310. <para>
  311. <emphasis><property>checksum</property></emphasis>: <constant>TRUE</constant>
  312. when the barcode should contain a checksum. The default value depends on the
  313. used adapter. Note that some adapters don't allow to set this option.
  314. </para>
  315. </listitem>
  316. <listitem>
  317. <para>
  318. <emphasis><property>options</property></emphasis>: Defines optional options for
  319. a self written adapters.
  320. </para>
  321. </listitem>
  322. </itemizedlist>
  323. </sect3>
  324. <sect3 id="zend.validate.set.barcode.basic">
  325. <title>Basic usage</title>
  326. <para>
  327. To validate if a given string is a barcode you just need to know its type. See the
  328. following example for an EAN13 barcode:
  329. </para>
  330. <programlisting language="php"><![CDATA[
  331. $valid = new Zend_Validate_Barcode('EAN13');
  332. if ($valid->isValid($input)) {
  333. // input appears to be valid
  334. } else {
  335. // input is invalid
  336. }
  337. ]]></programlisting>
  338. </sect3>
  339. <sect3 id="zend.validate.set.barcode.checksum">
  340. <title>Optional checksum</title>
  341. <para>
  342. Some barcodes can be provided with an optional checksum. These barcodes would be valid
  343. even without checksum. Still, when you provide a checksum, then you should also validate
  344. it. By default, these barcode types perform no checksum validation. By using the
  345. <property>checksum</property> option you can define if the checksum will be validated or
  346. ignored.
  347. </para>
  348. <programlisting language="php"><![CDATA[
  349. $valid = new Zend_Validate_Barcode(array(
  350. 'adapter' => 'EAN13',
  351. 'checksum' => false,
  352. ));
  353. if ($valid->isValid($input)) {
  354. // input appears to be valid
  355. } else {
  356. // input is invalid
  357. }
  358. ]]></programlisting>
  359. <note>
  360. <title>Reduced security by disabling checksum validation</title>
  361. <para>
  362. By switching off checksum validation you will also reduce the security of the used
  363. barcodes. Additionally you should note that you can also turn off the checksum
  364. validation for those barcode types which must contain a checksum value. Barcodes
  365. which would not be valid could then be returned as valid even if they are not.
  366. </para>
  367. </note>
  368. </sect3>
  369. <sect3 id="zend.validate.set.barcode.custom">
  370. <title>Writing custom adapters</title>
  371. <para>
  372. You may write custom barcode validators for usage with
  373. <classname>Zend_Validate_Barcode</classname>; this is often necessary when dealing with
  374. proprietary barcode types. To write your own barcode validator, you need the following
  375. information.
  376. </para>
  377. <itemizedlist>
  378. <listitem>
  379. <para>
  380. <emphasis>Length</emphasis>: The length your barcode must have. It can have one
  381. of the following values:
  382. </para>
  383. <itemizedlist>
  384. <listitem>
  385. <para>
  386. <emphasis>Integer</emphasis>: A value greater 0, which means that the
  387. barcode must have this length.
  388. </para>
  389. </listitem>
  390. <listitem>
  391. <para>
  392. <emphasis>-1</emphasis>: There is no limitation for the length of this
  393. barcode.
  394. </para>
  395. </listitem>
  396. <listitem>
  397. <para>
  398. <emphasis>"even"</emphasis>: The length of this barcode must have a
  399. even amount of digits.
  400. </para>
  401. </listitem>
  402. <listitem>
  403. <para>
  404. <emphasis>"odd"</emphasis>: The length of this barcode must have a
  405. odd amount of digits.
  406. </para>
  407. </listitem>
  408. <listitem>
  409. <para>
  410. <emphasis>array</emphasis>: An array of integer values. The length of
  411. this barcode must have one of the set array values.
  412. </para>
  413. </listitem>
  414. </itemizedlist>
  415. </listitem>
  416. <listitem>
  417. <para>
  418. <emphasis>Characters</emphasis>: A string which contains all allowed characters
  419. for this barcode. Also the integer value 128 is allowed, which means the first
  420. 128 characters of the ASCII table.
  421. </para>
  422. </listitem>
  423. <listitem>
  424. <para>
  425. <emphasis>Checksum</emphasis>: A string which will be used as callback for a
  426. method which does the checksum validation.
  427. </para>
  428. </listitem>
  429. </itemizedlist>
  430. <para>
  431. Your custom barcode validator must extend
  432. <classname>Zend_Validate_Barcode_AdapterAbstract</classname> or implement
  433. <interface>Zend_Validate_Barcode_AdapterInterface</interface>.
  434. </para>
  435. <para>
  436. As an example, let's create a validator that expects an even number of characters that
  437. include all digits and the letters 'ABCDE', and which requires a checksum.
  438. </para>
  439. <programlisting language="php"><![CDATA[
  440. class My_Barcode_MyBar extends Zend_Validate_Barcode_AdapterAbstract
  441. {
  442. protected $_length = 'even';
  443. protected $_characters = '0123456789ABCDE';
  444. protected $_checksum = '_mod66';
  445. protected function _mod66($barcode)
  446. {
  447. // do some validations and return a boolean
  448. }
  449. }
  450. $valid = new Zend_Validate_Barcode('My_Barcode_MyBar');
  451. if ($valid->isValid($input)) {
  452. // input appears to be valid
  453. } else {
  454. // input is invalid
  455. }
  456. ]]></programlisting>
  457. </sect3>
  458. </sect2>
  459. <!--
  460. vim:se ts=4 sw=4 et:
  461. -->