23 lines
576 B
PHP
23 lines
576 B
PHP
<?php
|
|
|
|
namespace App\Rules;
|
|
|
|
use Closure;
|
|
use Illuminate\Contracts\Validation\ValidationRule;
|
|
|
|
class UnsignedBigInteger implements ValidationRule
|
|
{
|
|
public function validate(string $attribute, mixed $value, Closure $fail): void
|
|
{
|
|
if (! ctype_digit((string) $value)) {
|
|
$fail("{$attribute} harus berupa bilangan bulat positif.");
|
|
|
|
return;
|
|
}
|
|
|
|
if (bccomp($value, '0') < 0 || bccomp($value, '18446744073709551615') > 0) {
|
|
$fail("{$attribute} harus berada di antara 0 dan 18446744073709551615.");
|
|
}
|
|
}
|
|
}
|