2.0.0 • Published 5 years ago

domain-name-regex v2.0.0

Weekly downloads
30
License
-
Repository
github
Last release
5 years ago

Domain Name Regex

A regex to validate domain names.

Installation

npm install --save domain-name-regex

Usage

const domainNameRegex = require('domain-name-regex')

domainNameRegex.test('example.com')
//=> true

domainNameRegex.test('_sip.example.com')
//=> true

domainNameRegex.test('-invalid.com')
//=> false

domainNameRegex.test('invalid.123')
//=> false

Rules

  • Domain name length cannot exceed 253 characters
  • Label length cannot exceed 63 characters
  • Label can only consist of letters, digits, hyphens and underscores (LDHU)
  • Label cannot start or end with a hyphen
  • TLD cannot contain only numbers
  • TLD cannot contain any underscores