Networking
Hostname (Single Label, RFC 1123)
Validate a single-label hostname per RFC 1123: 1–63 chars, letters/digits/hyphens, can't start or end with hyphen.
Try it in RegexPro →Available in
Pattern
regexengine-agnostic
^[a-zA-Z0-9](?:[a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?$Raw source: ^[a-zA-Z0-9](?:[a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?$
How it works
^[a-zA-Z0-9] requires the first character to be a letter or digit. (?:[a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])? optionally matches up to 61 more characters (letters, digits, hyphens) followed by a letter/digit ending — preventing trailing hyphens. Combined max length: 63 characters per RFC 1123.
Examples
Input
web-01Matches
web-01
Input
host123Matches
host123
Input
-bad-startNo match
—Common use cases
- •Kubernetes pod and service name validation
- •DNS label sanity checking
- •Container hostname enforcement
- •Server provisioning input validation
Related patterns
Kubernetes Pod Name (RFC 1123)
IdentifiersValidate Kubernetes pod names per the RFC 1123 DNS label rules — lowercase, ≤63 chars, no leading/trailing hyphen.
Private IP Address (RFC 1918)
NetworkingMatch IPv4 addresses in the RFC 1918 private ranges: 10/8, 192.168/16, and 172.16/12.
MAC Address
NetworkingMatch 48-bit MAC addresses written with colon or hyphen separators (e.g. 00:1A:2B:3C:4D:5E).
Domain Name
NetworkingMatch fully-qualified domain names like example.com or api.sub.example.co.uk.