parfum/app/Rules/PhoneNumber.php

22 lines
593 B
PHP

<?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".');
}
}
}