feat(rule): add PhoneNumber custmo rule for reusability

This commit is contained in:
Yoga Pangestu 2025-09-18 20:43:36 +07:00
parent 9385b54a06
commit e5754f93c4

21
app/Rules/PhoneNumber.php Normal file
View File

@ -0,0 +1,21 @@
<?php
namespace App\Rules;
use Closure;
use Illuminate\Contracts\Validation\ValidationRule;
class PhoneNumber implements ValidationRule
{
/**
* Run the validation rule.
*
* @param \Closure(string, ?string=): \Illuminate\Translation\PotentiallyTranslatedString $fail
*/
public function validate(string $attribute, mixed $value, Closure $fail): void
{
if (! preg_match('/^\d{4} \d{4} \d{3,5}$/', $value)) {
$fail('Format :attribute tidak valid. Harus seperti "0812 3456 789", "0812 3456 7890" atau "0812 3456 78901".');
}
}
}