41 lines
1005 B
PHP
41 lines
1005 B
PHP
<?php
|
|
|
|
// namespace App\Rules;
|
|
|
|
// use Closure;
|
|
// use Illuminate\Contracts\Validation\ValidationRule;
|
|
|
|
// class GhanaPhoneRule implements ValidationRule
|
|
// {
|
|
// /**
|
|
// * Run the validation rule.
|
|
// *
|
|
// * @param \Closure(string, ?string=): \Illuminate\Translation\PotentiallyTranslatedString $fail
|
|
// */
|
|
// public function validate(string $attribute, mixed $value, Closure $fail): void
|
|
// {
|
|
// //
|
|
// }
|
|
// }
|
|
namespace App\Rules;
|
|
|
|
use Illuminate\Contracts\Validation\Rule;
|
|
|
|
class GhanaPhoneRule implements Rule
|
|
{
|
|
public function passes($attribute, $value)
|
|
{
|
|
// Ghana phone numbers: start with 0 or +233, followed by 9 digits
|
|
// return preg_match('/^(?:\+233|0)[0-9]{9}$/', $value);
|
|
return preg_match('/^(?:\+233|233|0)[0-9]{9}$/', $value);
|
|
#/^(?:\+233|233|0)[0-9]{9}$/
|
|
|
|
}
|
|
|
|
public function message()
|
|
{
|
|
return 'Please enter a valid Ghanaian phone number (e.g., 024XXXXXXX or +23324XXXXXXX).';
|
|
}
|
|
}
|
|
|