feat: E.164 phone validation and storage with libphonenumber
- Add giggsey/libphonenumber-for-php, PhoneNumberNormalizer, ValidPhoneNumber rule - Store subscribers as E.164; mutator normalizes on save; optional phone required from form block - Migration to normalize legacy subscriber phones; Mailwizz/search/UI/tests updated - Add run-deploy-from-local.sh and PREREGISTER_DEFAULT_PHONE_REGION in .env.example Made-with: Cursor
This commit is contained in:
33
app/Rules/ValidPhoneNumber.php
Normal file
33
app/Rules/ValidPhoneNumber.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Rules;
|
||||
|
||||
use App\Services\PhoneNumberNormalizer;
|
||||
use Closure;
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
|
||||
final class ValidPhoneNumber implements ValidationRule
|
||||
{
|
||||
public function __construct(
|
||||
private readonly PhoneNumberNormalizer $normalizer
|
||||
) {}
|
||||
|
||||
public function validate(string $attribute, mixed $value, Closure $fail): void
|
||||
{
|
||||
if ($value === null || $value === '') {
|
||||
return;
|
||||
}
|
||||
|
||||
if (! is_string($value)) {
|
||||
$fail(__('Please enter a valid phone number.'));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ($this->normalizer->normalizeToE164(trim($value)) === null) {
|
||||
$fail(__('Please enter a valid phone number.'));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user