メインコンテンツまでスキップ
Version: Fegg 5.x(開発版)

Validation::url

Check URL format

Description​

public boolean Validation::url( string $name, mixed $value, [ mixed $code = '' ] )

Valid when the value starts with http://, https:// or ftp:// and contains only the characters allowed in a URL.

An empty value ('', null, '0', whitespace only) is not checked and returns true: combine with Validation::required when the field is required. When $name already has an error, the check is skipped and returns false, so only the first error of each field is kept.

Arguments​

NameData typeDefaultRemarks
$namestringField name (key of the error message)
$valuemixedValue to check
$codemixed''Error code, array of error code and parameters, or error message (see Configuration)

Example​

Controller
use Fegg\Validation;

$validation = new Validation();

$validation->url('success', 'https://example.com/', '<strong>URL</strong> の形式が正しくありません'); // -> true
$validation->url('failed', 'javascript:alert(1)', '<strong>URL</strong> の形式が正しくありません'); // -> false

var_dump($validation->getErrorMessage());
// -> array('failed' => '<strong>URL</strong> の形式が正しくありません')
メモ

The default validation_error_message.php has no @url code. Pass the error message itself, or add the code to your site/config/validation_error_message.php.