arubacao/tld-checker

Top Level Domain (TLD) validation library for PHP

Maintainers

Package info

github.com/arubacao/tld-checker

pkg:composer/arubacao/tld-checker

Statistics

Installs: 1 675 957

Dependents: 2

Suggesters: 0

Stars: 72

Open Issues: 0

2.0.2 2026-05-31 07:50 UTC

This package is auto-updated.

Last update: 2026-05-31 07:50:34 UTC


README

Latest Version on Packagist CI IANA TLD Update Total Downloads

This package allows validation of top level domains against the official The DNS Root Zone database from iana.org.
Use this to validate e.g. domains or email addresses.

The DNS Root Zone is the upper-most part of the DNS hierarchy, and involves delegating administrative responsibility of “top-level domains”, which are the last segment of a domain name, such as .com, .uk and .nz.

The database is stored locally and automatically updated for new database versions.

Installation

Install this package via composer:

composer require arubacao/tld-checker

Laravel

Laravel auto-discovery registers the service provider for supported Laravel versions. If auto-discovery is disabled in your application, register the provider manually:

// config/app.php

'providers' => [
    // Other Service Providers
    Arubacao\TldChecker\TldCheckerServiceProvider::class,
],

Notes:

  • arubacao/tld-checker is tested with GitHub Actions for PHP 8.1 - 8.5 & Laravel 9.x - 13.x.

Usage

Check a TLD using Validator::isTld():

use Arubacao\TldChecker\Validator;

Validator::isTld('com');        // true
Validator::isTld('CN');         // true (case insensitiv)
Validator::isTld('москва');     // true (works with internationalized domain name (IDN) | unicode)
Validator::isTld('XN--CZRS0T'); // true (works with encoded IDN | 商店)
Validator::isTld('.org');       // true (allows dot prefix)
Validator::isTld('apricot');    // false

Check if a string ends with a valid TLD using Validator::endsWithTld():

use Arubacao\TldChecker\Validator;

Validator::endsWithTld('apple.com');                            // true
Validator::endsWithTld('NEWS.CN');                              // true (case insensitiv)
Validator::endsWithTld('müller.vermögensberater');              // true (works with internationalized domain name (IDN) | unicode)
Validator::endsWithTld('xn--mller-kva.xn--vermgensberater-ctb');// true (works with encoded IDN | müller.vermögensberater)
Validator::endsWithTld('farming.apricot');                      // false

This package extends the Laravel Validator with these 2 methods:

  • is_tld
  • ends_with_tld

Use them as follows:

$request->validate([
    'tld' => 'required|is_tld',
    'email' => 'required|ends_with_tld'
]);

Testing

composer test

Maintenance

Refresh the generated IANA database locally:

composer build

The repository also has a scheduled GitHub Actions workflow that runs every Sunday at 04:01 UTC. If IANA has published a new root zone version, the workflow commits the refreshed src/RootZoneDatabase.php file and tags the next patch release so Packagist can pick it up.

Contributing

Please see CONTRIBUTING for details.

Credits

License

The MIT License (MIT). Please see License File for more information.