Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
is-valid-domain
Advanced tools
The is-valid-domain npm package is used to validate domain names. It checks if a given string is a valid domain name according to the rules specified in various domain name standards.
Basic Domain Validation
This feature allows you to check if a given string is a valid domain name. The function returns true if the domain is valid and false otherwise.
const isValidDomain = require('is-valid-domain');
console.log(isValidDomain('example.com')); // true
console.log(isValidDomain('invalid_domain')); // false
Subdomain Validation
This feature allows you to validate subdomains. It ensures that subdomains follow the correct format and rules.
const isValidDomain = require('is-valid-domain');
console.log(isValidDomain('sub.example.com')); // true
console.log(isValidDomain('sub..example.com')); // false
Top-Level Domain (TLD) Validation
This feature checks if the domain has a valid top-level domain (TLD). It ensures that the TLD is recognized and valid.
const isValidDomain = require('is-valid-domain');
console.log(isValidDomain('example.xyz')); // true
console.log(isValidDomain('example.invalidtld')); // false
The validator package is a library of string validators and sanitizers. It includes a function `isFQDN` that can be used to validate domain names. Compared to is-valid-domain, validator offers a broader range of validation functions beyond just domain validation.
The valid-url package provides functions to validate URLs and URIs. While it can validate domain names as part of a URL, it is more focused on the overall URL structure rather than just the domain. It is less specialized than is-valid-domain for domain-specific validation.
The is-url package is a simple utility to check if a string is a valid URL. It includes domain validation as part of its URL validation process. However, it is not as focused on domain-specific rules as is-valid-domain.
Validate domain name in JavaScript
https://lab.miguelmota.com/is-valid-domain
npm install is-valid-domain
const isValidDomain = require('is-valid-domain')
isValidDomain('example.com') // true
isValidDomain('foo.example.com') // true
isValidDomain('bar.foo.example.com') // true
isValidDomain('exa-mple.co.uk') // true
isValidDomain('xn--80ak6aa92e.com') // true
isValidDomain('_dnslink.ipfs.io') // true
isValidDomain('exa_mple.com') // false
isValidDomain('-example.co.uk') // false
isValidDomain('example') // false
isValidDomain('ex*mple.com') // false
isValidDomain('*.example.com') // false
isValidDomain('*.com') // false
isValidDomain(3434) // false
isValidDomain('foo.example.com', {subdomain: true}) // true
isValidDomain('foo.example.com', {subdomain: false}) // false
isValidDomain('*.example.com', {wildcard: false}) // false
isValidDomain('*.example.com', {wildcard: true}) // true
isValidDomain('*.example.com', {subdomain: false, wildcard: true}) // false
isValidDomain('はじめよう.みんな') // false
isValidDomain('はじめよう.みんな', {allowUnicode: true}) // true
isValidDomain('ai.') // false
isValidDomain('ai.', {topLevel: true}) // true
view more examples
npm test
Adding new domains:
data/second_level_domains.csv
npm run generate
to generate JSON map filenpm test
Q: Why is trailing dot .
in domain names verified as true
?
FAQs
Validate domain name
We found that is-valid-domain demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.