Skip to main content
Network & Web · In-Browser Regular Expression Lab

Domain Name Regex — Match FQDN and Hostnames

Validates Fully Qualified Domain Names (FQDN) adhering to DNS hostname specification (RFC 1035).

Flags:
//none
Match Found
Load Sample:
Match Inspection & Details1 match
Match #1:castov.com

Test Samples Verification Matrix

Expected Valid Samples (Should Match)

castov.com Pass
api.v2.service.cloud Pass
my-awesome-domain.org Pass

Expected Invalid Samples (Must Reject)

-bad.com Rejected (Pass)
domain..com Rejected (Pass)
invalid_char.com Rejected (Pass)
test.c Rejected (Pass)
Code Implementation Generator
// JavaScript / TypeScript (ES6+)
const pattern = /^(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}$/;
const text = "castov.com";

const isMatch = pattern.test(text);
console.log("Is Match:", isMatch);

if (isMatch) {
  const matches = text.match(pattern);
  console.log("Matches:", matches);
}

Regular Expression Token Breakdown

Ensures each label is 1-63 chars long, doesn't start or end with a hyphen, and terminates with a valid TLD. Each component of the regular expression serves a distinct syntactical purpose as mapped below:

Token PatternName / ComponentFunction & Rule
^StartStarts at string beginning.
[a-zA-Z0-9]First CharDNS labels cannot start with hyphens.
[a-zA-Z0-9-]{0,61}Label BodyAllows letters, numbers, and interior hyphens.
\.Dot separatorSeparates DNS subdomain and domain labels.
[a-zA-Z]{2,}$TLD SuffixTop-level domain of at least 2 characters.

Frequently Asked Questions

Are underscores allowed in domain names?
Standard hostnames do not permit underscores; only DNS records like SRV or DKIM use underscores.
Browse All 40 Patterns