Validation::password
Check allowed character to Password
Description
public boolean Validation::password( string $name, mixed $value, [ mixed $code = '', boolean $mixedLettersFlag = false ] )
Arguments
Name | Data type | Default | Remarks |
---|---|---|---|
$name | string | Item label | |
$value | mixed | Check field value | |
$code | mixed | "" | Error code or Error message |
$mixedLettersFlag | boolean | false | Required mixed letters alphanum flag |
Example
Controller
$validation = $this->getClass('Validation');
// If $value is alphanumeric
$successName = 'Success Field';
$successVar = 'abcdefhijk';
$validation->password('success', $successVar, array('@password', $successName));
var_dump($validation->isError()); // -> false
var_dump($validation->getErrorMessage()); // -> null
// If $value is not alphanumeric
$failedName = 'Failed Field';
$failedVar = 'パスワード';
$validation->password('failed', $failedVar, array('@password', $failedName));
var_dump($validation->isError()); // -> true
var_dump($validation->getErrorMessage());
// -> "failed" => "<strong>Failed Field</strong> は登録できない形式です"
Optional Flag
Controller
// If $value is alphabet with disabled mixed letter flag
$successName = 'Success Field';
$successVar = 'abcdefhijk';
$validation->password('success', $successVar, array('@password', $successName));
var_dump($validation->isError()); // -> false
var_dump($validation->getErrorMessage()); // -> null
// If $value is alphabet with enabled mixed letter flag
$failedName = 'Failed Field';
$failedVar = 'abcdefhijk';
$validation->password('failed', $failedVar, array('@password_mixed_letters', $failedName), true);
var_dump($validation->isError()); // -> true
var_dump($validation->getErrorMessage());
// -> "failed" => "<strong>Failed Field</strong> は半角英数の混合で入力してください"