Click to See Complete Forum and Search --> : How to validate a user inputted domain being a top level domain?


Red Squirrel
November 15th, 2009, 09:30 PM
How would I go about validating that a user inputted domain is a top level domain, and not a sub domain?

ex:

www.example.com = invalid
example.on.ca = valid
example.com = valid
com = invalid

Right now I am doing an explode and discarding the first portion (ex: example.on.ca becomes on.ca), then checking if the rest resolves, if it resolves, it's invalid. This is not fool proof though, is there a better way?