Download the PHP package countriesdb/validator without Composer
On this page you can find all versions of the php package countriesdb/validator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download countriesdb/validator
More information about countriesdb/validator
Files in countriesdb/validator
Package validator
Short Description PHP validation client for CountriesDB with Laravel validation rules and a standalone Http-based validator for country and subdivision code checks against the CountriesDB backend API.
License proprietary
Homepage https://nayee.net
Informations about the package validator
countriesdb/validator
Backend validation package for CountriesDB. Provides server-side validation for country and subdivision codes using ISO 3166-1 and ISO 3166-2 standards.
📖 Full Documentation | 🌐 Website
Important: This package only provides validation methods. Data fetching for frontend widgets must be done through frontend packages (@countriesdb/widget-core, @countriesdb/widget).
Getting Started
⚠️ API Key Required: This package requires a CountriesDB private API key to function. You must create an account at countriesdb.com to obtain your private API key. Test accounts are available with limited functionality.
- 🔑 Get your API key - Create an account and get your private key
- 📚 View documentation - Complete API reference and examples
- 💬 Support - Get help and support
Features
- ✅ Laravel Validation Rules - Drop-in validation rules (
ValidCountry,ValidSubdivision) for Laravel forms - ✅ Standalone Validator - Use the
Validatorclass directly in any PHP application - ✅ ISO 3166 Compliant - Validates ISO 3166-1 (countries) and ISO 3166-2 (subdivisions) codes
- ✅ Multiple Validation Options - Support for
follow_upward,follow_related, andallow_parent_selection - ✅ Batch Validation - Validate multiple countries or subdivisions in a single request
- ✅ Laravel 9-12 Support - Compatible with Laravel 9.0, 10.0, 11.0, and 12.0
- ✅ Detailed Error Messages - Returns specific error messages from the CountriesDB API
Installation
Usage
Standalone Validator
Laravel Validation Rules
Configuration
Add to your config/services.php:
Using Validation Rules
API Reference
Validator
Main validator class.
Constructor
Parameters:
apiKey(required): Your CountriesDB API keybackendUrl(optional): Backend API URL (defaults tohttps://api.countriesdb.com)
Methods
validateCountry(code, followUpward?)
Validate a single country code.
Parameters:
code(string): ISO 3166-1 alpha-2 country codefollowUpward(bool): Check if country is referenced in a subdivision (default:false)
Returns: array with valid (bool) and optional message (string|null)
validateCountries(codes)
Validate multiple country codes.
Parameters:
codes(array): Array of ISO 3166-1 alpha-2 country codes
Returns: array of results with code, valid, and optional message
validateSubdivision(code, country, followRelated?, allowParentSelection?)
Validate a single subdivision code.
Parameters:
code(string|null): Subdivision code (e.g., 'US-CA') or null/empty stringcountry(string): ISO 3166-1 alpha-2 country codefollowRelated(bool): Check if subdivision redirects to another country (default:false)allowParentSelection(bool): Allow selecting parent subdivisions (default:false)
Returns: array with valid (bool) and optional message (string|null)
validateSubdivisions(codes, country, allowParentSelection?)
Validate multiple subdivision codes.
Parameters:
codes(array): Array of subdivision codes or null/empty stringscountry(string): ISO 3166-1 alpha-2 country codeallowParentSelection(bool): Allow selecting parent subdivisions (default:false)
Returns: array of results with code, valid, and optional message
Laravel Rules
ValidCountry
Laravel validation rule for country codes.
ValidSubdivision
Laravel validation rule for subdivision codes.
Examples
End-to-end samples
A full Laravel application example using this package is available in the countriesdb/examples repository:
php/backend-laravel– Full Laravel application using this package's validation rules (ValidCountryandValidSubdivision)
The example includes setup instructions and demonstrates all validation scenarios with working API routes.
Manual Validation in Controllers
If you prefer to validate manually in your controllers instead of using Laravel validation rules:
Requirements
- PHP 8.0+
- Laravel 9.0+ (or illuminate/http ^9.0|^10.0|^11.0|^12.0)
- Valid CountriesDB API key
License
Proprietary (NAYEE LLC)
Copyright (c) NAYEE LLC. All rights reserved.
This software is the proprietary property of NAYEE LLC. For licensing inquiries, please contact NAYEE LLC.
All versions of validator with dependencies
illuminate/http Version ^9.0|^10.0|^11.0|^12.0
illuminate/validation Version ^9.0|^10.0|^11.0|^12.0