File tree 2 files changed +52
-0
lines changed 2 files changed +52
-0
lines changed Original file line number Diff line number Diff line change
1
+ Validator
2
+ =========
3
+
4
+ .. toctree ::
5
+ :maxdepth: 2
6
+
7
+ introduction
Original file line number Diff line number Diff line change
1
+ .. index ::
2
+ single: Validator
3
+ single: Components; Validator
4
+
5
+ The Validator Component
6
+ =======================
7
+
8
+ The Validator component provides tools to validate values following the
9
+ `JSR-303 Bean Validation specification `_.
10
+
11
+ Installation
12
+ ------------
13
+
14
+ You can install the component in 2 different ways:
15
+
16
+ * :doc: `Install it via Composer </components/using_components >` (``symfony/validator `` on `Packagist `_);
17
+ * Use the official Git repository (https://github.com/symfony/Validator).
18
+
19
+ Usage
20
+ -----
21
+
22
+ The Validator component allows you to use very advanced validation rules, but
23
+ it is also really easy to do very minor validation. For instance, if you want
24
+ to validate a string against a specific length, the only code you need is::
25
+
26
+ use Symfony\Component\Validator\Validation;
27
+ use Symfony\Component\Validator\Constraints\Length;
28
+
29
+ $validator = Validation::createValidator();
30
+
31
+ $violations = $validator->validateValue('Bernhard', new Length(array('min' => 10)));
32
+
33
+ if (0 !== count($violations)) {
34
+ // there are errors, let's show them
35
+ foreach ($violations as $violation) {
36
+ echo $violation->getMessage().'<br>';
37
+ }
38
+ }
39
+
40
+ Sections
41
+ --------
42
+
43
+ * :doc: `/components/validator/configuration `
44
+
45
+ .. _`JSR-303 Bean Validation specification` : http://jcp.org/en/jsr/detail?id=303
You can’t perform that action at this time.
0 commit comments