Postal Code Rule
Validate Postal Codes for Individual Countries
117k Downloads / Month
Open Source MIT License
117k Downloads / Month
Open Source MIT License
Explore how to validate international postal codes with the additional validation rules of Intervention Validation for your Laravel application.
public Intervention\Validation\Rules\Postalcode::__construct(array $countrycodes = [])
The field under validation must be a postal code of the given country.
Array of allowed country code strings in ISO-639-1 format.
use Illuminate\Support\Facades\Validator;
use Intervention\Validation\Rules\Postalcode;
$validator = Validator::make($request->all(), [
'attribute-key' => new Postalcode(['de', 'nl']),
]);
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.
The key where the country code is stored in the validation data.
use Illuminate\Support\Facades\Validator;
use Intervention\Validation\Rules\Postalcode;
$validator = Validator::make($request->all(), [
'attribute-key' => Postalcode::reference('country'),
]);
Edit