I haven't been able to find this one and what I'm trying isn't quite working out for me.
I want to match only domains that:
Example domains that would match:
Example domains that would not match:
What I've currently got:
/^(?!:\/\/)(^[a-zA-Z0-9])?.[a-zA-Z0-9-]+\.[a-zA-Z]{2,6}?$/i
It's not matching protocols, allowing hyphen inside the domain, not allowing trailing characters after the TLD, and is allowing a subdomain (but only 1 character).
I still need to allow subdomains of any length, not allow www.subdomain.domain.com and not allow a leading hyphen.
The domain name should be a-z or A-Z or 0-9 and hyphen (-). The domain name should be between 1 and 63 characters long. The domain name should not start or end with a hyphen(-) (e.g. -geeksforgeeks.org or geeksforgeeks.org-). The last TLD (Top level domain) must be at least two characters and a maximum of 6 characters.
Any string containing at least one dot is potentially a valid fqdn. The usage of the "host" command makes sure the string resolves to an ip address, which means it is actually a fqdn.
A FQDN is a domain name that includes a host name, a root domain and a top level domain. It may also include additional subdomains between the root domain and the host name. Almost all individual parts of a FQDN are technically subdomains. The only part of a domain that isn't a subdomain is the root domain.
Try
/^(?!:\/\/)([a-zA-Z0-9]+\.)?[a-zA-Z0-9][a-zA-Z0-9-]+\.[a-zA-Z]{2,6}?$/i
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With