Regex for Validating a Domain Name

Matches a domain made of one or more labels separated by dots, ending in a TLD.

Published October 12, 2026

Matches a domain made of one or more labels separated by dots, ending in a TLD.

Key points

  • Doesn't validate that the TLD is actually a registered one (like .com or .dev) — it just checks the general shape

Example

^([a-z0-9-]+\.)+[a-z]{2,}$
More General articles