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

Validation::required

Check required

Description​

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

A string is valid when it is not empty after trimming ('0' is valid). For an array, only the first element is checked: it must not be '' or null.

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->required('name', 'John', array('@required', 'Name')); // -> true
$validation->required('mail', '', array('@required', 'Email')); // -> false

var_dump($validation->isError()); // -> true
var_dump($validation->getErrorMessage());
// -> array('mail' => '<strong>Email</strong> をご入力ください')