Zend_Validate-PostCode.xml 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <sect2 id="zend.validate.set.post_code">
  4. <title>PostCode</title>
  5. <para>
  6. <classname>Zend_Validate_PostCode</classname> allows you to determine if a given value is a
  7. valid postal code. Postal codes are specific to cities, and in some locales termed
  8. <acronym>ZIP</acronym> codes.
  9. </para>
  10. <para>
  11. <classname>Zend_Validate_PostCode</classname> knows more than 160 different postal code
  12. formates. To select the correct format there are 2 ways. You can either use a fully
  13. qualified locale or you can set your own format manually.
  14. </para>
  15. <para>
  16. Using a locale is more convenient as Zend Framework already knows the appropriate postal
  17. code format for each locale; however, you need to use the fully qualified locale (one
  18. containing a region specifier) to do so. For instance, the locale "de" is a locale but
  19. could not be used with <classname>Zend_Validate_PostCode</classname> as it does not include
  20. the region; "de_AT", however, would be a valid locale, as it specifies the region code
  21. ("AT", for Austria).
  22. </para>
  23. <programlisting language="php"><![CDATA[
  24. $validator = new Zend_Validate_PostCode('de_AT');
  25. ]]></programlisting>
  26. <para>
  27. When you don't set a locale yourself, then <classname>Zend_Validate_PostCode</classname>
  28. will use the application wide set locale, or, when there is none, the locale returned by
  29. <classname>Zend_Locale</classname>.
  30. </para>
  31. <programlisting language="php"><![CDATA[
  32. // application wide locale within your bootstrap
  33. $locale = new Zend_Locale('de_AT');
  34. Zend_Registry::set('Zend_Locale', $locale);
  35. $validator = new Zend_Validate_PostCode();
  36. ]]></programlisting>
  37. <para>
  38. You can also change the locale afterwards by calling <methodname>setLocale()</methodname>.
  39. And of course you can get the actual used locale by calling
  40. <methodname>getLocale()</methodname>.
  41. </para>
  42. <programlisting language="php"><![CDATA[
  43. $validator = new Zend_Validate_PostCode('de_AT');
  44. $validator->setLocale('en_GB');
  45. ]]></programlisting>
  46. <para>
  47. Postal code formats themself are simply regular expression strings. When the international
  48. postal code format, which is used by setting the locale, does not fit your needs, then you
  49. can also manually set a format by calling <methodname>setFormat()</methodname>.
  50. </para>
  51. <programlisting language="php"><![CDATA[
  52. $validator = new Zend_Validate_PostCode('de_AT');
  53. $validator->setFormat('AT-\d{5}');
  54. ]]></programlisting>
  55. <note>
  56. <title>Conventions for self defined formats</title>
  57. <para>
  58. When using self defined formats you should omit the starting (<command>'/^'</command>)
  59. and ending tags (<command>'$/'</command>). They are attached automatically.
  60. </para>
  61. <para>
  62. You should also be aware that postcode values are always be validated in a strict way.
  63. This means that they have to be written standalone without additional characters when
  64. they are not covered by the format.
  65. </para>
  66. </note>
  67. <sect3 id="zend.validate.set.post_code.constructor">
  68. <title>Constructor options</title>
  69. <para>
  70. At it's most basic, you may pass either a <classname>Zend_Locale</classname> object or a
  71. string representing a fully qualified locale to the constructor of
  72. <classname>Zend_Validate_PostCode</classname>.
  73. </para>
  74. <programlisting language="php"><![CDATA[
  75. $validator = new Zend_Validate_PostCode('de_AT');
  76. $validator = new Zend_Validate_PostCode($locale);
  77. ]]></programlisting>
  78. <para>
  79. Additionally, you may pass either an array or a <classname>Zend_Config</classname>
  80. object to the constructor. When you do so, you must include either the key "locale" or
  81. "format"; these will be used to set the appropriate values in the validator object.
  82. </para>
  83. <programlisting language="php"><![CDATA[
  84. $validator = new Zend_Validate_PostCode(array(
  85. 'locale' => 'de_AT',
  86. 'format' => 'AT_\d+'
  87. ));
  88. ]]></programlisting>
  89. </sect3>
  90. <sect3 id="zend.validate.set.post_code.options">
  91. <title>Supported options for Zend_Validate_PostCode</title>
  92. <para>
  93. The following options are supported for <classname>Zend_Validate_PostCode</classname>:
  94. </para>
  95. <itemizedlist>
  96. <listitem>
  97. <para>
  98. <emphasis><property>format</property></emphasis>: Sets a postcode format which
  99. will be used for validation of the input.
  100. </para>
  101. </listitem>
  102. <listitem>
  103. <para>
  104. <emphasis><property>locale</property></emphasis>: Sets a locale from which the
  105. postcode will be taken from.
  106. </para>
  107. </listitem>
  108. </itemizedlist>
  109. </sect3>
  110. </sect2>
  111. <!--
  112. vim:se ts=4 sw=4 et:
  113. -->