Domain name regex pattern

Copy and test a JavaScript regex for domain names, with examples and a one-click link to the regex tester.

Domain name regex pattern

Validate whole value

Use anchors to check whether the complete value matches.

Regex: ^(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z]{2,63}$

Flags: i

Search in text

Find matching fragments inside a larger block of text.

Regex: \b(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z]{2,63}\b

Flags: gi

Examples that match

  • example.com
  • sub.domain.co.uk

Examples that do not match

  • -example.com
  • localhost