# is-valid-hostname

> Validate hostname based on RFC-1123

Latest version **1.0.2** (published 2021-08-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install is-valid-hostname
pnpm add is-valid-hostname
yarn add is-valid-hostname
bun add is-valid-hostname
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2021-08-22 |
| First published | 2020-02-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 12.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Miguel Mota |
| Maintainers | miguelmota |
| Keywords | valid, validate, validator, check, checker, domain, subdomain, wildcard, host, hostname, rfc1123, rfc3696, rfc952, rfc1034, rfc1738, rfc4697 |

## Links

- npm: https://www.npmjs.com/package/is-valid-hostname
- Repository: https://github.com/miguelmota/is-valid-hostname
- Issues: https://github.com/miguelmota/is-valid-hostname/issues
- npm.io page: https://npm.io/package/is-valid-hostname

## Recent versions

- 1.0.2 (latest) — 2021-08-22
- 1.0.1 — 2021-06-08
- 1.0.0 — 2020-12-22
- 0.1.1 — 2020-10-16
- 0.1.0 — 2020-08-20
- 0.0.1 — 2020-02-26

## README

# is-valid-hostname

> Validate hostname in JavaScript based on [RFC-1123](https://tools.ietf.org/html/rfc1123).

## Demo

[https://lab.miguelmota.com/is-valid-hostname](https://lab.miguelmota.com/is-valid-hostname)

## Install

```bash
npm install is-valid-hostname
```

## Usage

```javascript
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/test.js).

## Test

```bash
npm test
```

## FAQ

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

  - A: Numbers in TLD are allowed under RFC-1123. See [this answer](https://stackoverflow.com/a/53875771/1439168) for more information.

## License

[MIT](LICENSE)

---
_Source: https://npm.io/package/is-valid-hostname · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
