• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

How to validate a domain?

Red Squirrel

No Lifer
What is the best way to programaticly validate a domain name?

At first I was thinking, easy, just need to make sure it's in format "word.ext"

Then I just make sure that word and ext don't use any special characters.

If it's www.word.ext then it is invalid because there's 3 sections, I only want 2. (don't care about subdomains in this particular case)

But here's my delima. There are domain TLDs like co.uk.

So how would I handle that? Do I need to tell my program what every single domain extension is? How do programs like cpanel do it?
 
Here's a list of TLDs. You could probably write a script to pull the values into an xml file or some other persistent structure.

https://wiki.mozilla.org/TLD_List

Or you could just do a name lookup on it and see if you get a valid record back.
 
Hmm given that's from iana that's quite official right? Think I might go ahead and make my program use that. It will have it's own list but have an option to update with that list.
 
Ran into an issue. That list only has the main TLDs but not the "Sub" TLDs like co.uk and stuff. So I don't know how to make my program know the difference between:

subdomain.domain.com

and

domain.co.uk

The 2nd one should either be rejected or truncated as I only want domain.com while the 2nd is valid because co.uk is actually a tld and not a domain.

This is a program where users will enter data, so I have to make it fool proof or it could render the entire hosting environment screwed up, like if someone decides to add co.uk as a domain then nobody will be able to add something.co.uk as the other person will own that domain. Or do I just let them put whatever they want and solve these issues as they come?

This is for a control panel, so it's equivalent to "addon domains" in cpanel. Anyone know how cpanel handles this? I don't have a cpanel server to test with.
 
Back
Top