Validation::userid
Check user ID format
Description
public boolean Validation::userid( string $name, mixed $value, [ mixed $code = '' ] )
Valid when the value contains only 0-9, a-z, A-Z, -, _ and ..
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 | |
| $code | mixed | '' | Error code, array of error code and parameters, or error message (see Configuration) |
Example
Controller
use Fegg\Validation;
$validation = new Validation();
$validation->userid('success', 'john.doe_01', '<strong>User ID</strong> は登録できない形式です'); // -> true
$validation->userid('failed', 'john doe', '<strong>User ID</strong> は登録できない形式です'); // -> false
var_dump($validation->getErrorMessage());
// -> array('failed' => '<strong>User ID</strong> は登録できない形式です')
note
The default validation_error_message.php has no @userid code. Pass the error message itself, or add the code to your site/config/validation_error_message.php.