GithubHelp home page GithubHelp logo

tld-checker's Introduction

Top Level Domain (TLD) validation library for PHP

Latest Version on Packagist Build Status Codecov Quality Score 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

If you would like to use arubacao/tld-checker with the Laravel Validator, you must also register the service provider:
(only required for Laravel <=5.4, for Laravel >=5.5 auto-discovery is enabled.)

// config/app.php

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

Notes:

  • arubacao/tld-checker is functional and fully tested for PHP 7.0 - 7.3 & Laravel 5.0 - 6.0.

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

Contributing

Please see CONTRIBUTING for details.

Credits

License

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

tld-checker's People

Contributors

arubacao avatar lukaszwit avatar szepeviktor avatar daniel-farina avatar tomvo avatar andrewboerema avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.