1 <?xml version="1.0" encoding="UTF-8"?>
3 <sect2 id="zend.validate.set.int">
7 <classname>Zend_Validate_Int</classname> validates if a given value is an integer. Also
8 localized integer values are recognised and can be validated.
11 <sect3 id="zend.validate.set.int.options">
12 <title>Supported options for Zend_Validate_Int</title>
15 The following options are supported for <classname>Zend_Validate_Int</classname>:
21 <emphasis><property>locale</property></emphasis>: Sets the locale which will be
22 used to validate localized integers.
28 <sect3 id="zend.validate.set.int.basic">
29 <title>Simple integer validation</title>
32 The simplest way to validate an integer is by using the system settings. When no option
33 is used, the environment locale is used for validation:
36 <programlisting language="php"><![CDATA[
37 $validator = new Zend_Validate_Int();
39 $validator->isValid(1234); // returns true
40 $validator->isValid(1234.5); // returns false
41 $validator->isValid('1,234'); // returns true
45 In the above example we expected that our environment is set to "en" as locale. As you
46 can see in the third example also grouping is recognised.
50 <sect3 id="zend.validate.set.int.localized">
51 <title>Localized integer validation</title>
54 Often it's useful to be able to validate also localized values. Integer values are often
55 written different in other countries. For example using english you can write "1234" or
56 "1,234". Both are integer values but the grouping is optional. In german for example you
57 may write "1.234" and in french "1 234".
61 <classname>Zend_Validate_Int</classname> is able to validate such notations. But it is
62 limited to the locale you set. This means that it not simply strips off the separator,
63 it validates if the correct separator is used. See the following code:
66 <programlisting language="php"><![CDATA[
67 $validator = new Zend_Validate_Int(array('locale' => 'de'));
69 $validator->isValid(1234); // returns true
70 $validator->isValid("1,234"); // returns false
71 $validator->isValid("1.234"); // returns true
75 As you can see, by using a locale, your input is validated localized. Using the english
76 notation you get a <constant>FALSE</constant> when the locale forces a different
81 The locale can also be set afterwards by using <methodname>setLocale()</methodname> and
82 retrieved by using <methodname>getLocale()</methodname>.