is-valid-host
v1.0.1
Published
Validates if string is a valid host based on RFC-7230.
Downloads
759
Maintainers
Readme
is-valid-host
Validates if string is a valid host based on RFC-7230.
Demo
https://lab.miguelmota.com/is-valid-host
Install
npm install is-valid-host
Usage
const isValidHost = require('is-valid-host')
isValidHost('localhost') // true
isValidHost('127.0.0.1') // true
isValidHost('example.com') // true
isValidHost('foo.example.com') // true
isValidHost('bar.foo.example.com') // true
isValidHost('exa-mple.co.uk') // true
isValidHost('xn--80ak6aa92e.com') // true
isValidHost('example.com:3000') // true
isValidHost('127.0.0.1:3000') // true
isValidHost('exa_mple.com') // false
isValidHost('-example.com') // false
isValidHost('-example.com:3000') // false
View more examples.
Test
npm test