Dependency free domain name syntax validator with TLD checking and IDN support. See below examples to check what the validator checks for:
example.com
sub.example.com // allowSubdomain options is requried
exa-mple.com
xn--c1yn36f.com // allowIdn option is required
*.wildcard.com // allowWildcard and allowSubdomain options are required
123
123.123 // checkTld option is required
example
exam_ple.com
-example.com
example-.com
exa--mple.com
example.doesnotexist // checkTld option is required
xn--c1yn--bb.com
*.com
example.*.com
Install the library with npm --save is-domain-valid
const isDomainValid = require('../is-domain-valid');
const res = isDomainValid('example.com');
if (res.result) {
console.log('Domain is valid');
} else {
console.error(`Domain is not valid because of: ${res.message}`);
}
Options can be passed as a second argument in isDomainValid
function:
const defaultOptions = {
checkTld: true,
allowIdn: true,
allowSubdomain: true,
allowWildcard: false
};
const res = isDomainValid('example.com', defaultOptions);
Push requests are very welcome. Run tests with npm run tests
and then build the library with npm run build
.
Adam Blok: https://github.com/adamblok
MIT