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-01

Matches

  • web-01

Input

host123

Matches

  • host123

Input

-bad-start

No match

Common use cases

  • Kubernetes pod and service name validation
  • DNS label sanity checking
  • Container hostname enforcement
  • Server provisioning input validation