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
| Name | Data type | Default | Remarks |
|---|---|---|---|
| $name | string | Field name (key of the error message) | |
| $value | mixed | Value to check | |
| $length | numeric | Minimum number of characters | |
| $code | mixed | '' | 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> 文字以上で入力してください')