Filippo Bertilotti
2024-07-22 0991a9fb42afabd45d2b7504b84d6484b241c35d
commit | author | age
9f6455 1 <?php
DC 2
3 namespace App\Rules;
4
5 use Illuminate\Contracts\Validation\Rule;
6
7 class FilenameWithExtension implements Rule
8 {
9     /**
10      * Create a new rule instance.
11      *
12      * @return void
13      */
14     public function __construct()
15     {
16
17     }
18
19     /**
20      * Determine if the validation rule passes.
21      *
22      * @param  string  $attribute
23      * @param  mixed  $value
24      * @return bool
25      */
26     public function passes($attribute, $value)
27     {
28         // Check if there are valid base64 characters
29         if (!preg_match('/^[\w,\s-]+\.[A-Za-z]{3}$/', $value)) {
30             return false;
31         }
32
33         return true;
34     }
35
36     /**
37      * Get the validation error message.
38      *
39      * @return string
40      */
41     public function message()
42     {
43         return 'The name for the attached binary file must include a correct file extension (es: .jpg)';
44     }
45 }