How to validate a domain name using Regex & Php?

前端 未结 6 688
失恋的感觉
失恋的感觉 2020-12-03 05:27

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         


        
6条回答
  •  甜味超标
    2020-12-03 05:45

    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.

提交回复
热议问题