pixelpeter/laravel-isocodes-validation

Laravel 8+ wrapper for the IsoCodes Validation library from ronanguilloux
143,047 5
Install
composer require pixelpeter/laravel-isocodes-validation
Latest Version:v13.0.0
PHP:^8.3|^8.4|^8.5
License:GPL-3.0-or-later
Last Updated:Sep 17, 2026
Links: GitHub  ·  Packagist
Maintainer: pixelpeter

Laravel 12+ IsoCodes Validation

Latest Version on Packagist Total Downloads Software License Coverage Status Tests Fix PHP code style issues PHPStan dependabot-auto-merge

A simple Laravel 12+ wrapper for the IsoCodes Validation library from ronanguilloux.

Version overview

From v13.0.0 on, the package major version matches the highest Laravel major version it supports, so ^13.0 covers Laravel 13.x and 12.x. This is the only maintained line: master is where it is developed, and the v13.x branch tracks it and carries the released state.

Laravel php composer branch
13.x, 12.x 8.5, 8.4, 8.3 ^13.0 master, v13.x

Deprecated releases

Earlier releases stay installable and unchanged, but they are no longer maintained: they receive no fixes and no further releases. Laravel 11.x and 10.x are past their security support window, and Composer refuses to install them because of published security advisories.

Laravel php composer tag status
12.x, 11.x, 10.x 8.4, 8.3, 8.2 ^12.0 v12.1.0 deprecated, superseded by ^13.0
11.x, 10.x 8.3, 8.2, 8.1 ^10.0 v10.1.0 deprecated, no successor
9.x, 8.x 8.2, 8.1, 8.0 ^8.0 v8.1.1 deprecated, no successor

Installation

Install With Composer

composer require pixelpeter/laravel-isocodes-validation

Usage

Simple examples

// Checking out your e-commerce shopping cart?
$payload = [
    'creditcard' => '12345679123456'
];
$rules = [
    'creditcard' => 'creditcard'
];

$validator = Validator::make($payload, $rules);

Examples with reference parameter

Some rules need a reference to be validated against (e.g. country for zipcode).

Just pass the name of the field holding the reference to the rule.

// Sending letters to the Labrador Islands ?
$payload = [
    'zipcode' => 'A0A 1A0',
    'country' => 'CA'
];
$rules = [
    'zipcode' => 'zipcode:country'
];

$validator = Validator::make($payload, $rules);

// Publishing books?
$payload = [
    'isbn' => '2-2110-4199-X',
    'isbntype' => 13
];
$rules = [
    'zipcode' => 'isbn:isbntype'
];

$validator = Validator::make($payload, $rules);

Example with arrays and dot notation

(added in v3.x)

As suggested by @otr-tomek I've added support for all validation methods using arrays in dot notation as an input.

$payload = [
    'data' => [
        [
            'country' => 'DE',
            'zipcode' => 63741
        ],
        [
            'country' => 'AT',
            'zipcode' => 1180
        ]
  ] 
];

$validator = Validator::make($payload, [
    'data.*.zipcode' => 'zipcode:data.*.country'
]);

Validation error messages

Error messages can contain the name and value of the field and the value of the reference

$payload = [
    'phonenumber' => 'invalid',
    'country' => 'GB'
];
$rules = [
    'phonenumber' => 'phonenumber:country'
];

$validator = Validator::make($payload, $rules);

print $validator->errors()->first(); // The value "invalid" of phonenumber is not valid for "GB".

More Examples

Refer to IsoCodes Validation library for more examples and documentation.

Testing

Run the tests with:

vendor/bin/phpunit

License

GNU General Public License v3.0 only. Please see License File for more information.

Related Packages

pixelpeter/laravel5-isocodes-validation

Laravel 5 wrapper for the IsoCodes Validation library from ronanguilloux

87,867 19
prettus/laravel-validation

Laravel Validation Service

11,862,350 406
propaganistas/laravel-phone

Adds phone number functionality to Laravel based on Google's libphonenumber API.

43,538,120 3,026
skysplit/laravel5-intl-translation

Laravel 5 package for better translation syntax using php-intl extension

106,815 10
proengsoft/laravel-jsvalidation

Validate forms transparently with Javascript reusing your Laravel Validation Rul...

2,445,464 1,140