Skip to main content
Version: Fegg 5.x (next)

Validation::minlength

Check minimum character length

Description​

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

Valid when the number of characters (mb_strlen() in UTF-8) is $length or more. The @minlength message takes the label and the length as parameters.

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
$lengthnumericMinimum number of characters
$codemixed''Error code, array of error code and parameters, or error message (see Configuration)

Example​

Controller
use Fegg\Validation;

$validation = new Validation();

$validation->minlength('success', 'secret_123', 8, array('@minlength', 'Password', 8)); // -> true
$validation->minlength('failed', 'abc', 8, array('@minlength', 'Password', 8)); // -> false

var_dump($validation->getErrorMessage());
// -> array('failed' => '<strong>Password</strong> は <strong>8</strong> 文字以上で入力してください')