31 lines
709 B
PHP
Executable File
31 lines
709 B
PHP
Executable File
<?php
|
|
|
|
namespace Modules\Admin\app\Rules;
|
|
|
|
use Closure;
|
|
use Illuminate\Contracts\Validation\ValidationRule;
|
|
|
|
class TimezoneOffsetRule implements ValidationRule
|
|
{
|
|
public static function check($value)
|
|
{
|
|
$pattern = '/^[+-]\d{2}:\d{2}$/';
|
|
return preg_match($pattern, $value) === 1;
|
|
}
|
|
|
|
static public function message(): string
|
|
{
|
|
return "Your timezone offset is incorrectly transmitted. Please format as follows: '+00:00', '+11:00'!";
|
|
}
|
|
|
|
/**
|
|
* Run the validation rule.
|
|
*/
|
|
public function validate(string $attribute, mixed $value, Closure $fail): void
|
|
{
|
|
if (!$this->check($value)) {
|
|
$fail($this->message());
|
|
}
|
|
}
|
|
}
|