Sorry, no results were found for this search.

Postal Code Rule

Validate Postal Codes for Individual Countries

172k Downloads / Month

Open Source MIT License

Validate international postal codes in Laravel with Intervention Validation. Multi-country ZIP/postal codes.

public Intervention\Validation\Rules\Postalcode::__construct(array $countrycodes = [])

The field under validation must be a postal code of the given country.

Parameters

countrycodes

Array of allowed country code strings in ISO-639-1 format.

Example

use Illuminate\Support\Facades\Validator;
use Intervention\Validation\Rules\Postalcode;

$validator = Validator::make($request->all(), [
    'attribute-key' => new Postalcode(['de', 'nl']),
]);

Validate by Reference

public Intervention\Validation\Rules\Postalcode::reference(string $reference)

The field under validation must be a postal code of the given country. The value to be validated is obtained from the sent data via a reference. This can be useful if, for example, you select a country elsewhere and this selection is used to determine how the zip code is validated.

Parameters

reference

The key where the country code is stored in the validation data.

Example

use Illuminate\Support\Facades\Validator;
use Intervention\Validation\Rules\Postalcode;

$validator = Validator::make($request->all(), [
    'attribute-key' => Postalcode::reference('country'),
]);
Edit