Ok first i have to said that i checked like 20 Questions about domain names but no one fit my needs or have uncomplete / obslote answers or start to talk about http adresses or dns.
Saying that i gonna continue,
As far i know ( if i'm wrong with something tell me and i will update this as faster as i can ) :
domainName.subdomain.otherSubdomain.otherSubdomain.domainExtension
- Domain names, subdomains and domain extension cannot exceed 63
- Domain extension have to be greater than 2
- Domain extension just can contain letters.
- Domain names, subdomains cannot start with dash - or dot .
- Domain names and subdomains cannot contain two dashes in a row
- Domain names and subdomains can contain letters, numbers and dashes
- A Domain can have multiples subdomains
The total length of the domain cannot exceed of 253 ( the dots count ! )
A real domain extension has a trailing dot so the full length would be 254 remember that
www.google.es
is a shorthand ofwww.google.es.
So the trailing dot would be optional.
- A Domain cannot contain two dots in a row
The first part would be not allow dashes or dots at the beginning
^(?![\-\.])
The last part would be the domain extension with a minimum of two and have an optional trailing dot
([a-z]{1,62}|[a-z]{1,62}+\.)$
The Regex would be something like this:
^(?![\-\.])[a-zA-Z0-9\.\-]{2,}+(?<![\-\.])([A\.][a-z]{1,62}|[A\.][a-z]{1,62}+\.)$
But this is passing internal double Dots and subdomains starting by dashes google..-subdomain.com
And still needs to check the max of 63 length, and the total length less than 253
I feel close but still missing something, or maybe doing in a harder way, so... can somebody fix this regex ?
Any help would be much appreciated.