0

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 of www.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.

Héctor León
  • 2,210
  • 2
  • 23
  • 36
  • I'm not sure what you intend to use it for but I urge you to either A) use an already existing solution, even if it just means finding an already tested regex or B) completely change the approach and try resolving the domain if it's applicable. What you are verifying is not really DNS standards compliant since a domain name can consist of a lot more chars than just A-Z and 0-9 (see RFC2181, section 11 for additional notes). – kb. Jun 28 '16 at 16:12
  • hi @kb., i saw this link about RFC2181 ( https://tools.ietf.org/html/rfc2181#section-11 ) but didn't see anything about chararcters allowed. Anyway if i opened this topic was because i didn't find a good one. All 'solutions' that i tried fail at some point ( double dot, dot and dash, length etc.... ) but if you know where find a good one that fit the most of my needs would be much appreciated if you put here. Thanks in advanced – Héctor León Jun 29 '16 at 17:30

0 Answers0