Issues (73)

src/Rules/ValidVatId.php (1 issue)

1
<?php
2
3
namespace Milwad\LaravelValidate\Rules;
4
5
use Illuminate\Contracts\Validation\Rule;
6
7
class ValidVatId implements Rule
8
{
9
    /**
10
     * Check VAT ID for validity.
11
     */
12
    public function passes($attribute, $value): bool
13
    {
14
        // Remove all characters except letters and numbers
15
        $value = preg_replace('/[^a-zA-Z0-9]/', '', $value);
16
17
        return preg_match('/[a-zA-Z]{2}[0-9]{0,12}$/', $value);
0 ignored issues
show
Bug Best Practice introduced by
The expression return preg_match('/[a-z...[0-9]{0,12}$/', $value) returns the type integer which is incompatible with the type-hinted return boolean.
Loading history...
18
    }
19
20
    /**
21
     * Get the validation error message.
22
     */
23
    public function message(): string
24
    {
25
        return __('validate.vat-id');
26
    }
27
}
28