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

Validation::password

Check password format

Description​

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

Valid when the value contains only 0-9, a-z, A-Z and -_@!#. With $mixedLettersFlag it must also contain at least one letter and one digit; use the error code @password_mixed_letters for that message. The length is not checked: combine with Validation::minlength.

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
$codemixed''Error code, array of error code and parameters, or error message (see Configuration)
$mixedLettersFlagbooleanfalsetrue: require both letters and digits

Example​

Controller
use Fegg\Validation;

$validation = new Validation();

$validation->password('success', 'secret_123', array('@password', 'Password')); // -> true
$validation->password('failed', 'pass word', array('@password', 'Password')); // -> false

var_dump($validation->getErrorMessage());
// -> array('failed' => '<strong>Password</strong> は登録できない形式です')

// Letters and digits are both required
$validation->password('password2', 'secret', array('@password_mixed_letters', 'Password'), true); // -> false