2

So i came across the following How to validate domain name in PHP?

But domain name registrars do not let you register the following two:

 is_valid_domain_name? [a.b]
 is_valid_domain_name? [xn--fsqu00a.xn--0zwm56d]

Because they do not allow you to register single letter/numeric domains, nor domains seperating words or letters/numbers with a fullstop or domains with symbols etc does that mean these domains are invalid and can never be used?

It makes me curious if this PHP code is accurate and how you know if you was to input a domain to it that could be registered?

The code accepts those two and they both can not be registered by any domain registrar I have found so I think this code would not be accurate.

Community
  • 1
  • 1
C0nw0nk
  • 870
  • 2
  • 13
  • 29
  • They even remove the full stop inbetween the two sections to the domain, It makes you think they treat it like a subdomain instead of a primary domain. – C0nw0nk Dec 08 '14 at 12:30

1 Answers1

0

You can give below rule a try instead. It works good for almost all domain names :)

^(([a-zA-Z]{1})|([a-zA-Z]{1}[a-zA-Z]{1})|([a-zA-Z]{1}[0-9]{1})|([0-9]{1}[a-zA-Z]{1})|([a-zA-Z0-9][a-zA-Z0-9-_]{1,61}[a-zA-Z0-9]))\.([a-zA-Z]{2,6}|[a-zA-Z0-9-]{2,30}\.[a-zA-Z]{2,3})$

Regular expression visualization

Debuggex Demo

Dipak G.
  • 715
  • 1
  • 4
  • 18
  • Thanks i will check it do you know if there are rules on different domain extensions regarding allowed and disallowed formats since on certain registrars they give me "invalid" on domain extensions but yet .com, .net etc they will say i can purchase that domain. – C0nw0nk Dec 08 '14 at 12:00
  • I suggest you first check the given rule and comments. – Dipak G. Dec 08 '14 at 12:02
  • It is very strange how even registrars validate this because your code will say "0-WH-AO14-0.COM-com.net" that is a valid domain all top world leading registrar sites i have tried say it is either a invalid domain or they drop the "COM-com" section after the first full stop. I want to be as accurate as possible for the purpose of a database project can not be logging invalid domains. – C0nw0nk Dec 08 '14 at 12:19