File tree Expand file tree Collapse file tree 6 files changed +102
-0
lines changed Expand file tree Collapse file tree 6 files changed +102
-0
lines changed Original file line number Diff line number Diff line change @@ -272,6 +272,8 @@ Below is list of all available validation rules
272
272
* [ uploaded_file] ( #rule-uploaded_file )
273
273
* [ default/defaults] ( #rule-default )
274
274
* [ email] ( #rule-email )
275
+ * [ uppercase] ( #rule-uppercase )
276
+ * [ lowercase] ( #rule-lowercase )
275
277
* [ alpha] ( #rule-alpha )
276
278
* [ numeric] ( #rule-numeric )
277
279
* [ alpha_num] ( #rule-alpha_num )
@@ -392,6 +394,16 @@ Validation passes because we sets default value for `enabled` and `published` to
392
394
393
395
The field under this validation must be valid email address.
394
396
397
+ <a id =" rule-uppercase " ></a >
398
+ #### uppercase
399
+
400
+ The field under this validation must be valid uppercase.
401
+
402
+ <a id =" rule-lowercase " ></a >
403
+ #### lowercase
404
+
405
+ The field under this validation must be valid lowercase.
406
+
395
407
<a id =" rule-alpha " ></a >
396
408
#### alpha
397
409
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Rakit \Validation \Rules ;
4
+
5
+ use Rakit \Validation \Rule ;
6
+
7
+ class Lowercase extends Rule
8
+ {
9
+
10
+ protected $ message = "The :attribute must be lowercase " ;
11
+
12
+ public function check ($ value )
13
+ {
14
+ return mb_strtolower ($ value , mb_detect_encoding ($ value )) === $ value ;
15
+ }
16
+
17
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Rakit \Validation \Rules ;
4
+
5
+ use Rakit \Validation \Rule ;
6
+
7
+ class Uppercase extends Rule
8
+ {
9
+
10
+ protected $ message = "The :attribute must be uppercase " ;
11
+
12
+ public function check ($ value )
13
+ {
14
+ return mb_strtoupper ($ value , mb_detect_encoding ($ value )) === $ value ;
15
+ }
16
+
17
+ }
Original file line number Diff line number Diff line change @@ -104,6 +104,8 @@ protected function registerBaseValidators()
104
104
'callback ' => new Rules \Callback ,
105
105
'before ' => new Rules \Before ,
106
106
'after ' => new Rules \After ,
107
+ 'lowercase ' => new Rules \Lowercase ,
108
+ 'uppercase ' => new Rules \Uppercase ,
107
109
'defaults ' => new Rules \Defaults ,
108
110
'default ' => new Rules \Defaults , // alias of defaults
109
111
];
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ use Rakit \Validation \Rules \Lowercase ;
4
+
5
+ class LowercaseTest extends PHPUnit_Framework_TestCase
6
+ {
7
+
8
+ public function setUp ()
9
+ {
10
+ $ this ->rule = new Lowercase ;
11
+ }
12
+
13
+ public function testValids ()
14
+ {
15
+ $ this ->assertTrue ($ this ->rule ->check ('username ' ));
16
+ $ this ->assertTrue ($ this ->rule ->check ('full name ' ));
17
+ $ this ->assertTrue ($ this ->rule ->check ('full_name ' ));
18
+ }
19
+
20
+ public function testInvalids ()
21
+ {
22
+ $ this ->assertFalse ($ this ->rule ->check ('USERNAME ' ));
23
+ $ this ->assertFalse ($ this ->rule ->check ('Username ' ));
24
+ $ this ->assertFalse ($ this ->rule ->check ('userName ' ));
25
+ }
26
+
27
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ use Rakit \Validation \Rules \Uppercase ;
4
+
5
+ class UppercaseTest extends PHPUnit_Framework_TestCase
6
+ {
7
+
8
+ public function setUp ()
9
+ {
10
+ $ this ->rule = new Uppercase ;
11
+ }
12
+
13
+ public function testValids ()
14
+ {
15
+ $ this ->assertTrue ($ this ->rule ->check ('USERNAME ' ));
16
+ $ this ->assertTrue ($ this ->rule ->check ('FULL NAME ' ));
17
+ $ this ->assertTrue ($ this ->rule ->check ('FULL_NAME ' ));
18
+ }
19
+
20
+ public function testInvalids ()
21
+ {
22
+ $ this ->assertFalse ($ this ->rule ->check ('username ' ));
23
+ $ this ->assertFalse ($ this ->rule ->check ('Username ' ));
24
+ $ this ->assertFalse ($ this ->rule ->check ('userName ' ));
25
+ }
26
+
27
+ }
You can’t perform that action at this time.
0 commit comments