Skip to content

Checks whether a given domain is correctly formatted and contains a valid Top Level Domain.

License

Notifications You must be signed in to change notification settings

Banidja/domain-tld-validator

Repository files navigation

Domain TLD Validator

This package provides a simple function to validate domain names based on general domain formatting rules and Top-Level Domain (TLD) verification. It checks whether a given domain is correctly formatted and contains a valid TLD.

Installation

npm install domain-tld-validator

Usage

import { validateDomain } from "domain-tld-validator";

console.log(validateDomain("google.com")); // true
console.log(validateDomain("sub.google.com")); // true
console.log(validateDomain("go-ogle.com")); // true
console.log(validateDomain("goo.gle.com")); // true
console.log(validateDomain("correct-format-with-dashes-google.com")); // true

console.log(validateDomain("goo gle.com")); // false
console.log(validateDomain("google.com.")); // false
console.log(validateDomain("google.whatever123")); // false
console.log(validateDomain(".google.com")); // false
console.log(validateDomain("google")); // false
console.log(validateDomain(".com")); // false

About

Checks whether a given domain is correctly formatted and contains a valid Top Level Domain.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published