opnform/app/Rules/ValidUrl.php

34 lines
701 B
PHP
Raw Permalink Normal View History

2023-10-17 07:09:45 +00:00
<?php
namespace App\Rules;
use Illuminate\Contracts\Validation\Rule;
class ValidUrl implements Rule
{
/**
* Determine if the validation rule passes.
*
* @param string $attribute
* @param mixed $value
* @return bool
*/
public function passes($attribute, $value)
{
// Define the regular expression to match the desired URL patterns
$pattern = '/^(https?:\/\/)?(www\.)?[\w.-]+\.\w+(:\d+)?(\/[^\s]*)?$/';
return preg_match($pattern, $value);
}
/**
* Get the validation error message.
*
* @return string
*/
public function message()
{
return 'The :attribute format is invalid.';
}
}