Domain Name Validation Regex
Validate domain names including subdomains. Matches domains like example.com and mail.example.org.
Pattern & Test String
About This Pattern
Pattern: ^(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}$
Flags: g
Results
Enter a regex pattern to see the results here.
Frequently Asked Questions
Does this support internationalized domain names (IDN)?
No, this pattern is for ASCII domains only. IDN domains use Punycode (xn--) which requires special handling.
Can it validate if a domain exists?
No, regex only validates format. To check if a domain exists, perform a DNS lookup.
Does this allow subdomains?
Yes, this pattern matches any number of subdomains like mail.server.example.com.
Practical Examples
Email Domain Validation
Extract and validate the domain part of email addresses.
Whitelist Management
Validate domains for allow/deny lists in security systems.
DNS Configuration
Validate domain names in DNS management interfaces.
Common Issues & Solutions
This pattern requires at least a 2-character TLD. Single-letter TLDs like .x won't match.
Domains can't start or end with hyphens, which this pattern prevents.
Maximum label length is 63 characters, enforced by {0,61} (accounting for required start/end characters).
For stricter validation, check against a list of valid TLDs.