Skip to main content
Version: Fegg 5.x

Validation::maxbyte

Check the maximum length in bytes

Description​

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

Valid when the byte length (strlen()) of the value is $byte or less. A Japanese character is 3 bytes in UTF-8.

Arguments​

NameData typeDefaultRemarks
$namestringField name (key of the error message)
$valuemixedValue to check
$bytenumericMaximum number of bytes
$codemixed''Error code, array of error code and parameters, or error message (see Configuration)

Example​

Controller
use Fegg\Tool\Validation;

$validation = new Validation();

$validation->maxbyte('success', 'abc', 5, '<strong>Name</strong> が長すぎます'); // -> true
$validation->maxbyte('failed', 'あいう', 5, '<strong>Name</strong> が長すぎます'); // -> false

var_dump($validation->getErrorMessage());
// -> array('failed' => '<strong>Name</strong> が長すぎます')
note

The default validation_error_message.php has no @maxbyte code. Pass the error message itself, or add the code to your site/config/validation_error_message.php.