File tree Expand file tree Collapse file tree 2 files changed +52
-0
lines changed Expand file tree Collapse file tree 2 files changed +52
-0
lines changed Original file line number Diff line number Diff line change 1313 'float_number ' => 'The :attribute must be a float number. ' ,
1414 'hash ' => 'The :attribute must be a hash of :algorithm algorithm. ' ,
1515 'image_url ' => 'The :attribute must be a valid image URL. ' ,
16+ 'jwt ' => 'The :attribute must have a valid format of JWT. ' ,
1617 'name ' => 'The :attribute must be a valid name. ' ,
1718 'phone ' => 'The :attribute must be a valid phone number. ' ,
1819 'username ' => 'The :attribute must be a valid username. ' ,
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Arifszn \AdvancedValidation \Rules ;
4+
5+ use Illuminate \Contracts \Validation \Rule ;
6+
7+ /**
8+ * The field under validation must have a valid format of JWT.
9+ *
10+ * @package Arifszn\AdvancedValidation\Rules
11+ */
12+ class Jwt implements Rule
13+ {
14+ /**
15+ * @var string
16+ */
17+ private $ errorMessage ;
18+
19+ /**
20+ * Create a new rule instance.
21+ *
22+ * @param string|null $errorMessage Custom error message.
23+ * @return void
24+ */
25+ public function __construct (string $ errorMessage = null )
26+ {
27+ $ this ->errorMessage = $ errorMessage ;
28+ }
29+
30+ /**
31+ * Determine if the validation rule passes.
32+ *
33+ * @param string $attribute
34+ * @param mixed $value
35+ * @return bool
36+ */
37+ public function passes ($ attribute , $ value )
38+ {
39+ return preg_match ('/^[a-zA-Z0-9-_]+\.[a-zA-Z0-9-_]+\.[a-zA-Z0-9-_]+$/ ' , $ value );
40+ }
41+
42+ /**
43+ * Get the validation error message.
44+ *
45+ * @return string
46+ */
47+ public function message ()
48+ {
49+ return $ this ->errorMessage ? $ this ->errorMessage : trans ('advancedValidation::validation.jwt ' );
50+ }
51+ }
You can’t perform that action at this time.
0 commit comments