is-valid-hostname
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

is-valid-hostname

Validate hostname in JavaScript based on RFC-1123.

Demo

https://lab.miguelmota.com/is-valid-hostname

Install

npm install is-valid-hostname

Usage

const isValidHostname = require('is-valid-hostname')

isValidHostname('localhost') // true
isValidHostname('example.com') // true
isValidHostname('foo.example.com') // true
isValidHostname('bar.foo.example.com') // true
isValidHostname('exa-mple.co.uk') // true
isValidHostname('xn--80ak6aa92e.com') // true
isValidHostname('9gag.com') // true
isValidHostname('8.8.8.8') // true
isValidHostname('127.0.0.1') // true
isValidHostname('exa_mple.com') // false
isValidHostname('-example.com') // false
isValidHostname('example.com:3000') // false
isValidHostname('8.8.8.8:3000') // false

View more examples.

Test

npm test

FAQ

  • Q: Why are numbers allowed in top-level domain?

    • A: Numbers in TLD are allowed under RFC-1123. See this answer for more information.

License

MIT

/is-valid-hostname/

    Package Sidebar

    Install

    npm i is-valid-hostname

    Weekly Downloads

    38,376

    Version

    1.0.2

    License

    MIT

    Unpacked Size

    13.1 kB

    Total Files

    12

    Last publish

    Collaborators

    • miguelmota