Skip to main content
Version: Fegg 5.x

Validation::zipcode

Check the format of a Japanese postal code

Description​

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

Valid when the value is 3 digits and 4 digits, with or without - between them (123-4567 or 1234567).

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)

Example​

Controller
use Fegg\Tool\Validation;

$validation = new Validation();

$validation->zipcode('success', '123-4567', array('@zipcode', 'Zip code')); // -> true
$validation->zipcode('failed', '123-456', array('@zipcode', 'Zip code')); // -> false

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