I want a solution to validate only domain names not full urls, The following example is what i\'m looking for:
domain.com -> true
domain.net -> true
do
Remember, regexes can only check to see if something is well formed. "www.idonotexistbecauseiammadeuponthespot.com" is well-formed, but doesn't actually exist... at the time of writing. ;) Furthermore, certain free web hosting providers (like Tripod) allow underscores in subdomains. This is clearly a violation of the RFCs, yet it sometimes works.
Do you want to check if the domain exists? Try dns_get_record instead of (just) a regex.