If you take a look at util.inc, there are useful functions to improve these checks, like is_domain, is_hostname, ...