Have ideas to improve npm?Join in the discussion! »

domain-name-regex
TypeScript icon, indicating that this package has built-in type declarations

2.0.0 • Public • Published

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

Keywords

none

Install

npm i domain-name-regex

DownloadsWeekly Downloads

38

Version

2.0.0

License

none

Unpacked Size

6.68 kB

Total Files

7

Last publish

Collaborators

  • avatar